<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 6.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css" integrity="sha256-CTSx/A06dm1B063156EVh15m6Y67pAjZZaQc89LLSrU=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.24/fancybox/fancybox.css" integrity="sha256-vQkngPS8jiHHH0I6ABTZroZk8NPZ7b+MUReOFE9UsXQ=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"rjyblog.gitee.io","root":"/","images":"/images","scheme":"Pisces","darkmode":false,"version":"8.18.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":null},"fold":{"enable":false,"height":500},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta property="og:type" content="website">
<meta property="og:title" content="任建勇的博客">
<meta property="og:url" content="https://rjyblog.gitee.io/page/2/index.html">
<meta property="og:site_name" content="任建勇的博客">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="Jason">
<meta property="article:tag" content="Android, Java, Kotlin, Flutter, 前端技术, 设计模式">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://rjyblog.gitee.io/page/2/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":true,"isPost":false,"lang":"zh-CN","comments":"","permalink":"","path":"page/2/index.html","title":""}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>任建勇的博客</title>
  








  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">任建勇的博客</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-overview-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Jason"
      src="/images/avatar.png">
  <p class="site-author-name" itemprop="name">Jason</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">66</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">13</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">23</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner index posts-expand">

    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/abd111cb.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/abd111cb.html" class="post-title-link" itemprop="url">Java动态代理</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-10-23 18:02:47" itemprop="dateCreated datePublished" datetime="2023-10-23T18:02:47+08:00">2023-10-23</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2024-01-06 22:27:58" itemprop="dateModified" datetime="2024-01-06T22:27:58+08:00">2024-01-06</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="JDK动态代理"><a href="#JDK动态代理" class="headerlink" title="JDK动态代理"></a>JDK动态代理</h2><p>通过<code>java.lang.reflect.Proxy</code>可以实现动态代理，但是这种方式只能作用于接口，如果一个类没有接口则无法实现动态代理。</p>
<figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//Interface是一个接口，InterfaceImpl是接口的实现类</span></span><br><span class="line"><span class="keyword">val</span> delegate = InterfaceImpl()</span><br><span class="line"><span class="keyword">val</span> proxy = Proxy.newProxyInstance(Interface::<span class="keyword">class</span>.java.classLoader, arrayOf(Interface::<span class="keyword">class</span>.java)</span><br><span class="line">) &#123; proxy, method, args -&gt;</span><br><span class="line">    <span class="keyword">if</span> (method.name == <span class="string">&quot;testMethod&quot;</span>) &#123;</span><br><span class="line">        <span class="comment">//可以打印日志等</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> (args != <span class="literal">null</span>) &#123;</span><br><span class="line">        method.invoke(delegate, *args)</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        method.invoke(delegate)</span><br><span class="line">    &#125;</span><br><span class="line">&#125; <span class="keyword">as</span> Interface</span><br></pre></td></tr></table></figure>

<h2 id="CGLIB实现动态代理"><a href="#CGLIB实现动态代理" class="headerlink" title="CGLIB实现动态代理"></a>CGLIB实现动态代理</h2><p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/cglib/cglib">CGLIB</a>通过动态生成一个代理类的子类来提供代理。但是对于final方法，是无法实现代理的。</p>
<h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://www.runoob.com/w3cnote/cglibcode-generation-library-intro.html">CGLIB(Code Generation Library) 介绍与原理</a><br><a target="_blank" rel="noopener external nofollow noreferrer" href="https://www.jianshu.com/p/9bcac608c714">动态代理底层实现</a></p>

          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/abd111cb.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/1b96348b.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/1b96348b.html" class="post-title-link" itemprop="url">通过自定义Service理解Binder</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-10-23 07:50:48" itemprop="dateCreated datePublished" datetime="2023-10-23T07:50:48+08:00">2023-10-23</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-11-18 08:32:16" itemprop="dateModified" datetime="2023-11-18T08:32:16+08:00">2023-11-18</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>本文创建了一个独立进程的service，通过bind方式来绑定服务，并通过binder与service进行交互。基于此来分析binder交互机制。</p>
<h2 id="Service的创建与使用"><a href="#Service的创建与使用" class="headerlink" title="Service的创建与使用"></a>Service的创建与使用</h2><p><strong>定义aidl接口：</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//IRemote.aidl</span></span><br><span class="line"><span class="keyword">interface</span> <span class="title class_">IRemote</span> &#123;</span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">setCallback</span><span class="params">(RemoteCallback callback)</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//RemoteCallback.aidl</span></span><br><span class="line"><span class="keyword">interface</span> <span class="title class_">RemoteCallback</span> &#123;</span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">callback</span><span class="params">(String content)</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>IRemote是service的对外接口，TalkCallback则用于从service回调client端，加入TalkCallback是为了更好的理解service和client相互调用的流程。<br>定义完aidl后，编译一遍项目，这样就可以生成对应的java类，对应的java类在<code>app/build/generated/aidl_source_output_dir</code>目录下。</p>
<p><strong>定义Service：</strong></p>
<figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">RemoveService</span> <span class="title">extends</span> <span class="title">Service</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> RemoveService() &#123;&#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> IBinder onBind(Intent intent) &#123;</span><br><span class="line">        <span class="keyword">return</span> binder;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">final</span> IBinder binder = new IRemote.Stub() &#123;</span><br><span class="line">        <span class="meta">@Override</span></span><br><span class="line">        <span class="keyword">public</span> void setCallback(RemoteCallback callback) throws RemoteException &#123;</span><br><span class="line">            <span class="comment">//收到client端的函数调用，并回调client端</span></span><br><span class="line">            callback.callback(<span class="string">&quot;I&#x27;m Service&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>因为我们要定义一个独立进程的service，所以在AndroidManifest.xml要声明<code>android:process</code>属性，如下：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">service</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:name</span>=<span class="string">&quot;.RemoveService&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:enabled</span>=<span class="string">&quot;true&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:exported</span>=<span class="string">&quot;false&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:process</span>=<span class="string">&quot;:remote&quot;</span>/&gt;</span></span><br></pre></td></tr></table></figure>

<p>这样一个独立进程的service就定义完成了，然后就可以使用了。</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/1b96348b.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/90f60c72.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/90f60c72.html" class="post-title-link" itemprop="url">Android WindowManager与Window</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-10-20 11:11:56" itemprop="dateCreated datePublished" datetime="2023-10-20T11:11:56+08:00">2023-10-20</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2024-01-06 11:39:25" itemprop="dateModified" datetime="2024-01-06T11:39:25+08:00">2024-01-06</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>先看下app端的类图结构：</p>
<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentstyletype="text/css" height="502px" preserveAspectRatio="none" style="width:831px;height:502px;background:#FFFFFF;" version="1.1" viewBox="0 0 831 502" width="831px" zoomAndPan="magnify"><defs/><g><!--class WindowManager--><g id="elem_WindowManager"><rect codeline="2" fill="#F1F1F1" height="48" id="WindowManager" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="151" x="169" y="115"/><ellipse cx="184" cy="131" fill="#B4A7E5" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M184.9531,127.7813 L186.6719,127.7813 C187.0625,127.7813 187.25,127.75 187.375,127.6719 C187.6406,127.5156 187.7813,127.2344 187.7813,126.9375 C187.7813,126.6719 187.6719,126.4063 187.4375,126.2344 C187.2656,126.125 187.125,126.0938 186.6719,126.0938 L181.5313,126.0938 C181.0938,126.0938 180.9688,126.1094 180.8125,126.2031 C180.5625,126.3594 180.4063,126.6563 180.4063,126.9375 C180.4063,127.2188 180.5469,127.4688 180.7656,127.6406 C180.9219,127.75 181.1094,127.7813 181.5313,127.7813 L183.25,127.7813 L183.25,134.2969 L181.5313,134.2969 C181.0938,134.2969 180.9688,134.3125 180.8125,134.4219 C180.5625,134.5781 180.4063,134.8594 180.4063,135.1563 C180.4063,135.4063 180.5469,135.6719 180.7656,135.8281 C180.9219,135.9531 181.125,136 181.5313,136 L186.6719,136 C187.4219,136 187.7813,135.7188 187.7813,135.1563 C187.7813,134.875 187.6719,134.625 187.4375,134.4531 C187.2656,134.3281 187.125,134.2969 186.6719,134.2969 L184.9531,134.2969 L184.9531,127.7813 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="119" x="198" y="135.8467">WindowManager</text><line style="stroke:#181818;stroke-width:0.5;" x1="170" x2="319" y1="147" y2="147"/><line style="stroke:#181818;stroke-width:0.5;" x1="170" x2="319" y1="155" y2="155"/></g><!--class Window--><g id="elem_Window"><rect codeline="3" fill="#F1F1F1" height="48" id="Window" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="88" x="288.5" y="7"/><ellipse cx="303.5" cy="23" fill="#A9DCDF" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M305.5781,24.8125 L305.9688,25.7969 L305.5781,25.7969 C305.125,25.7969 305.0156,25.8125 304.8594,25.9219 C304.6094,26.0781 304.4531,26.3594 304.4531,26.6563 C304.4531,26.9219 304.5938,27.1719 304.8125,27.3281 C304.9531,27.4531 305.1563,27.5 305.5781,27.5 L307.9375,27.5 C308.2969,27.5 308.5156,27.4688 308.6563,27.375 C308.9063,27.2344 309.0625,26.9375 309.0625,26.6563 C309.0625,26.375 308.9219,26.125 308.7031,25.9688 C308.5313,25.8281 308.375,25.7969 307.9063,25.7969 L304.5156,17.5938 L300.8438,17.5938 C300.3906,17.5938 300.2656,17.6094 300.1094,17.7031 C299.8594,17.875 299.7031,18.1563 299.7031,18.4375 C299.7031,18.7188 299.8438,18.9688 300.0625,19.1406 C300.2344,19.25 300.4063,19.2813 300.8438,19.2813 L301.9219,19.2813 L299.2813,25.7969 C298.8594,25.7969 298.7031,25.8125 298.5469,25.9219 C298.2969,26.0781 298.1406,26.3594 298.1406,26.6563 C298.1406,27.2188 298.5156,27.5 299.2656,27.5 L301.5313,27.5 C301.8906,27.5 302.1094,27.4688 302.2344,27.375 C302.5,27.2344 302.6406,26.9375 302.6406,26.6563 C302.6406,26.375 302.5156,26.125 302.2969,25.9531 C302.125,25.8281 301.9844,25.7969 301.5313,25.7969 L301.1406,25.7969 L301.5313,24.8125 L305.5781,24.8125 Z M304.875,23.1094 L302.2031,23.1094 L303.5469,19.8438 L304.875,23.1094 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="56" x="317.5" y="27.8467">Window</text><line style="stroke:#181818;stroke-width:0.5;" x1="289.5" x2="375.5" y1="39" y2="39"/><line style="stroke:#181818;stroke-width:0.5;" x1="289.5" x2="375.5" y1="47" y2="47"/></g><!--class Activity--><g id="elem_Activity"><rect fill="#F1F1F1" height="48" id="Activity" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="88" x="165.5" y="7"/><ellipse cx="180.5" cy="23" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M182.8438,18.6719 C181.9063,18.2344 181.3125,18.0938 180.4375,18.0938 C177.8125,18.0938 175.8125,20.1719 175.8125,22.8906 L175.8125,24.0156 C175.8125,26.5938 177.9219,28.4844 180.8125,28.4844 C182.0313,28.4844 183.1875,28.1875 183.9375,27.6406 C184.5156,27.2344 184.8438,26.7813 184.8438,26.3906 C184.8438,25.9375 184.4531,25.5469 183.9844,25.5469 C183.7656,25.5469 183.5625,25.625 183.375,25.8125 C182.9219,26.2969 182.9219,26.2969 182.7344,26.3906 C182.3125,26.6563 181.625,26.7813 180.8594,26.7813 C178.8125,26.7813 177.5156,25.6875 177.5156,23.9844 L177.5156,22.8906 C177.5156,21.1094 178.7656,19.7969 180.5,19.7969 C181.0781,19.7969 181.6875,19.9531 182.1563,20.2031 C182.6406,20.4844 182.8125,20.7031 182.9063,21.1094 C182.9688,21.5156 183,21.6406 183.1406,21.7656 C183.2813,21.9063 183.5156,22.0156 183.7344,22.0156 C184,22.0156 184.2656,21.875 184.4375,21.6563 C184.5469,21.5 184.5781,21.3125 184.5781,20.8906 L184.5781,19.4688 C184.5781,19.0313 184.5625,18.9063 184.4688,18.75 C184.3125,18.4844 184.0313,18.3438 183.7344,18.3438 C183.4375,18.3438 183.2344,18.4375 183.0156,18.75 L182.8438,18.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="56" x="194.5" y="27.8467">Activity</text><line style="stroke:#181818;stroke-width:0.5;" x1="166.5" x2="252.5" y1="39" y2="39"/><line style="stroke:#181818;stroke-width:0.5;" x1="166.5" x2="252.5" y1="47" y2="47"/></g><!--class PhoneWindow--><g id="elem_PhoneWindow"><rect fill="#F1F1F1" height="48" id="PhoneWindow" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="133" x="355" y="115"/><ellipse cx="370" cy="131" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M372.3438,126.6719 C371.4063,126.2344 370.8125,126.0938 369.9375,126.0938 C367.3125,126.0938 365.3125,128.1719 365.3125,130.8906 L365.3125,132.0156 C365.3125,134.5938 367.4219,136.4844 370.3125,136.4844 C371.5313,136.4844 372.6875,136.1875 373.4375,135.6406 C374.0156,135.2344 374.3438,134.7813 374.3438,134.3906 C374.3438,133.9375 373.9531,133.5469 373.4844,133.5469 C373.2656,133.5469 373.0625,133.625 372.875,133.8125 C372.4219,134.2969 372.4219,134.2969 372.2344,134.3906 C371.8125,134.6563 371.125,134.7813 370.3594,134.7813 C368.3125,134.7813 367.0156,133.6875 367.0156,131.9844 L367.0156,130.8906 C367.0156,129.1094 368.2656,127.7969 370,127.7969 C370.5781,127.7969 371.1875,127.9531 371.6563,128.2031 C372.1406,128.4844 372.3125,128.7031 372.4063,129.1094 C372.4688,129.5156 372.5,129.6406 372.6406,129.7656 C372.7813,129.9063 373.0156,130.0156 373.2344,130.0156 C373.5,130.0156 373.7656,129.875 373.9375,129.6563 C374.0469,129.5 374.0781,129.3125 374.0781,128.8906 L374.0781,127.4688 C374.0781,127.0313 374.0625,126.9063 373.9688,126.75 C373.8125,126.4844 373.5313,126.3438 373.2344,126.3438 C372.9375,126.3438 372.7344,126.4375 372.5156,126.75 L372.3438,126.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="101" x="384" y="135.8467">PhoneWindow</text><line style="stroke:#181818;stroke-width:0.5;" x1="356" x2="487" y1="147" y2="147"/><line style="stroke:#181818;stroke-width:0.5;" x1="356" x2="487" y1="155" y2="155"/></g><!--class WindowManagerImpl--><g id="elem_WindowManagerImpl"><rect fill="#F1F1F1" height="48" id="WindowManagerImpl" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="181" x="154" y="223"/><ellipse cx="169" cy="239" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M171.3438,234.6719 C170.4063,234.2344 169.8125,234.0938 168.9375,234.0938 C166.3125,234.0938 164.3125,236.1719 164.3125,238.8906 L164.3125,240.0156 C164.3125,242.5938 166.4219,244.4844 169.3125,244.4844 C170.5313,244.4844 171.6875,244.1875 172.4375,243.6406 C173.0156,243.2344 173.3438,242.7813 173.3438,242.3906 C173.3438,241.9375 172.9531,241.5469 172.4844,241.5469 C172.2656,241.5469 172.0625,241.625 171.875,241.8125 C171.4219,242.2969 171.4219,242.2969 171.2344,242.3906 C170.8125,242.6563 170.125,242.7813 169.3594,242.7813 C167.3125,242.7813 166.0156,241.6875 166.0156,239.9844 L166.0156,238.8906 C166.0156,237.1094 167.2656,235.7969 169,235.7969 C169.5781,235.7969 170.1875,235.9531 170.6563,236.2031 C171.1406,236.4844 171.3125,236.7031 171.4063,237.1094 C171.4688,237.5156 171.5,237.6406 171.6406,237.7656 C171.7813,237.9063 172.0156,238.0156 172.2344,238.0156 C172.5,238.0156 172.7656,237.875 172.9375,237.6563 C173.0469,237.5 173.0781,237.3125 173.0781,236.8906 L173.0781,235.4688 C173.0781,235.0313 173.0625,234.9063 172.9688,234.75 C172.8125,234.4844 172.5313,234.3438 172.2344,234.3438 C171.9375,234.3438 171.7344,234.4375 171.5156,234.75 L171.3438,234.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="149" x="183" y="243.8467">WindowManagerImpl</text><line style="stroke:#181818;stroke-width:0.5;" x1="155" x2="334" y1="255" y2="255"/><line style="stroke:#181818;stroke-width:0.5;" x1="155" x2="334" y1="263" y2="263"/></g><!--class WindowManagerGlobal--><g id="elem_WindowManagerGlobal"><rect codeline="8" fill="#F1F1F1" height="56.2656" id="WindowManagerGlobal" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="195" x="147" y="331"/><ellipse cx="162" cy="351.1328" fill="#FF7700" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M165.7813,347.1016 C165.7813,346.6641 165.7656,346.5234 165.6719,346.3672 C165.5313,346.1328 165.25,345.9766 164.9531,345.9766 C164.6094,345.9766 164.4688,346.1172 164.2969,346.5391 C163.7031,346.1641 162.9531,345.9766 162.0781,345.9766 C159.9688,345.9766 158.3906,347.2734 158.3906,348.9922 C158.3906,349.9609 158.9219,350.8672 159.7813,351.3516 C160.3281,351.6641 160.875,351.8359 161.9844,352.0234 C163.1406,352.2266 163.4063,352.2891 163.7656,352.4766 C164.1406,352.6797 164.375,353.0234 164.375,353.3828 C164.375,354.1172 163.3906,354.6641 162.1406,354.6641 C161.0156,354.6641 159.9375,354.1797 159.7656,353.5703 C159.6406,353.1016 159.6406,353.1016 159.5156,352.9922 C159.3594,352.8359 159.1406,352.7422 158.9063,352.7422 C158.625,352.7422 158.375,352.8672 158.2031,353.0859 C158.0938,353.2578 158.0469,353.4453 158.0469,353.8672 L158.0469,354.9922 C158.0469,355.7578 158.3281,356.1172 158.9219,356.1172 C159.1875,356.1172 159.3125,356.0547 159.5938,355.7109 C160.4375,356.1484 161.3281,356.3672 162.25,356.3672 C164.5781,356.3672 166.1406,355.1797 166.1406,353.4141 C166.1406,352.5234 165.8281,351.8359 165.1406,351.2891 C164.6094,350.8672 163.9688,350.6172 162.4844,350.3516 C161.2188,350.1172 161.125,350.0859 160.7969,349.9141 C160.4219,349.7266 160.1563,349.3359 160.1563,348.9766 C160.1563,348.2422 161.0156,347.6797 162.0781,347.6797 C163.1406,347.6797 163.9531,348.1484 164.1094,348.8203 C164.2188,349.3672 164.2188,349.3672 164.3438,349.5078 C164.4844,349.6328 164.7188,349.7422 164.9531,349.7422 C165.2188,349.7422 165.4688,349.6016 165.6406,349.3828 C165.75,349.2109 165.7813,349.0703 165.7813,348.6016 L165.7813,347.1016 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="71" x="222" y="347.1387">&#171;Singleton&#187;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="163" x="176" y="362.9639">WindowManagerGlobal</text><line style="stroke:#181818;stroke-width:0.5;" x1="148" x2="341" y1="371.2656" y2="371.2656"/><line style="stroke:#181818;stroke-width:0.5;" x1="148" x2="341" y1="379.2656" y2="379.2656"/></g><!--class ViewParent--><g id="elem_ViewParent"><rect codeline="10" fill="#F1F1F1" height="48" id="ViewParent" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="112" x="387.5" y="223"/><ellipse cx="402.5" cy="239" fill="#B4A7E5" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M403.4531,235.7813 L405.1719,235.7813 C405.5625,235.7813 405.75,235.75 405.875,235.6719 C406.1406,235.5156 406.2813,235.2344 406.2813,234.9375 C406.2813,234.6719 406.1719,234.4063 405.9375,234.2344 C405.7656,234.125 405.625,234.0938 405.1719,234.0938 L400.0313,234.0938 C399.5938,234.0938 399.4688,234.1094 399.3125,234.2031 C399.0625,234.3594 398.9063,234.6563 398.9063,234.9375 C398.9063,235.2188 399.0469,235.4688 399.2656,235.6406 C399.4219,235.75 399.6094,235.7813 400.0313,235.7813 L401.75,235.7813 L401.75,242.2969 L400.0313,242.2969 C399.5938,242.2969 399.4688,242.3125 399.3125,242.4219 C399.0625,242.5781 398.9063,242.8594 398.9063,243.1563 C398.9063,243.4063 399.0469,243.6719 399.2656,243.8281 C399.4219,243.9531 399.625,244 400.0313,244 L405.1719,244 C405.9219,244 406.2813,243.7188 406.2813,243.1563 C406.2813,242.875 406.1719,242.625 405.9375,242.4531 C405.7656,242.3281 405.625,242.2969 405.1719,242.2969 L403.4531,242.2969 L403.4531,235.7813 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="80" x="416.5" y="243.8467">ViewParent</text><line style="stroke:#181818;stroke-width:0.5;" x1="388.5" x2="498.5" y1="255" y2="255"/><line style="stroke:#181818;stroke-width:0.5;" x1="388.5" x2="498.5" y1="263" y2="263"/></g><!--class ViewRootImpl--><g id="elem_ViewRootImpl"><rect fill="#F1F1F1" height="48" id="ViewRootImpl" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="133" x="377" y="335"/><ellipse cx="392" cy="351" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M394.3438,346.6719 C393.4063,346.2344 392.8125,346.0938 391.9375,346.0938 C389.3125,346.0938 387.3125,348.1719 387.3125,350.8906 L387.3125,352.0156 C387.3125,354.5938 389.4219,356.4844 392.3125,356.4844 C393.5313,356.4844 394.6875,356.1875 395.4375,355.6406 C396.0156,355.2344 396.3438,354.7813 396.3438,354.3906 C396.3438,353.9375 395.9531,353.5469 395.4844,353.5469 C395.2656,353.5469 395.0625,353.625 394.875,353.8125 C394.4219,354.2969 394.4219,354.2969 394.2344,354.3906 C393.8125,354.6563 393.125,354.7813 392.3594,354.7813 C390.3125,354.7813 389.0156,353.6875 389.0156,351.9844 L389.0156,350.8906 C389.0156,349.1094 390.2656,347.7969 392,347.7969 C392.5781,347.7969 393.1875,347.9531 393.6563,348.2031 C394.1406,348.4844 394.3125,348.7031 394.4063,349.1094 C394.4688,349.5156 394.5,349.6406 394.6406,349.7656 C394.7813,349.9063 395.0156,350.0156 395.2344,350.0156 C395.5,350.0156 395.7656,349.875 395.9375,349.6563 C396.0469,349.5 396.0781,349.3125 396.0781,348.8906 L396.0781,347.4688 C396.0781,347.0313 396.0625,346.9063 395.9688,346.75 C395.8125,346.4844 395.5313,346.3438 395.2344,346.3438 C394.9375,346.3438 394.7344,346.4375 394.5156,346.75 L394.3438,346.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="101" x="406" y="355.8467">ViewRootImpl</text><line style="stroke:#181818;stroke-width:0.5;" x1="378" x2="509" y1="367" y2="367"/><line style="stroke:#181818;stroke-width:0.5;" x1="378" x2="509" y1="375" y2="375"/></g><!--class IWindowSession--><g id="elem_IWindowSession"><rect codeline="12" fill="#F1F1F1" height="48" id="IWindowSession" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="146" x="195.5" y="447"/><ellipse cx="210.5" cy="463" fill="#B4A7E5" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M211.4531,459.7813 L213.1719,459.7813 C213.5625,459.7813 213.75,459.75 213.875,459.6719 C214.1406,459.5156 214.2813,459.2344 214.2813,458.9375 C214.2813,458.6719 214.1719,458.4063 213.9375,458.2344 C213.7656,458.125 213.625,458.0938 213.1719,458.0938 L208.0313,458.0938 C207.5938,458.0938 207.4688,458.1094 207.3125,458.2031 C207.0625,458.3594 206.9063,458.6563 206.9063,458.9375 C206.9063,459.2188 207.0469,459.4688 207.2656,459.6406 C207.4219,459.75 207.6094,459.7813 208.0313,459.7813 L209.75,459.7813 L209.75,466.2969 L208.0313,466.2969 C207.5938,466.2969 207.4688,466.3125 207.3125,466.4219 C207.0625,466.5781 206.9063,466.8594 206.9063,467.1563 C206.9063,467.4063 207.0469,467.6719 207.2656,467.8281 C207.4219,467.9531 207.625,468 208.0313,468 L213.1719,468 C213.9219,468 214.2813,467.7188 214.2813,467.1563 C214.2813,466.875 214.1719,466.625 213.9375,466.4531 C213.7656,466.3281 213.625,466.2969 213.1719,466.2969 L211.4531,466.2969 L211.4531,459.7813 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="114" x="224.5" y="467.8467">IWindowSession</text><line style="stroke:#181818;stroke-width:0.5;" x1="196.5" x2="340.5" y1="479" y2="479"/><line style="stroke:#181818;stroke-width:0.5;" x1="196.5" x2="340.5" y1="487" y2="487"/></g><!--class IWindow_Stub--><g id="elem_IWindow_Stub"><rect codeline="15" fill="#F1F1F1" height="48" id="IWindow_Stub" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="128" x="684.5" y="335"/><ellipse cx="699.5" cy="351" fill="#A9DCDF" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M701.5781,352.8125 L701.9688,353.7969 L701.5781,353.7969 C701.125,353.7969 701.0156,353.8125 700.8594,353.9219 C700.6094,354.0781 700.4531,354.3594 700.4531,354.6563 C700.4531,354.9219 700.5938,355.1719 700.8125,355.3281 C700.9531,355.4531 701.1563,355.5 701.5781,355.5 L703.9375,355.5 C704.2969,355.5 704.5156,355.4688 704.6563,355.375 C704.9063,355.2344 705.0625,354.9375 705.0625,354.6563 C705.0625,354.375 704.9219,354.125 704.7031,353.9688 C704.5313,353.8281 704.375,353.7969 703.9063,353.7969 L700.5156,345.5938 L696.8438,345.5938 C696.3906,345.5938 696.2656,345.6094 696.1094,345.7031 C695.8594,345.875 695.7031,346.1563 695.7031,346.4375 C695.7031,346.7188 695.8438,346.9688 696.0625,347.1406 C696.2344,347.25 696.4063,347.2813 696.8438,347.2813 L697.9219,347.2813 L695.2813,353.7969 C694.8594,353.7969 694.7031,353.8125 694.5469,353.9219 C694.2969,354.0781 694.1406,354.3594 694.1406,354.6563 C694.1406,355.2188 694.5156,355.5 695.2656,355.5 L697.5313,355.5 C697.8906,355.5 698.1094,355.4688 698.2344,355.375 C698.5,355.2344 698.6406,354.9375 698.6406,354.6563 C698.6406,354.375 698.5156,354.125 698.2969,353.9531 C698.125,353.8281 697.9844,353.7969 697.5313,353.7969 L697.1406,353.7969 L697.5313,352.8125 L701.5781,352.8125 Z M700.875,351.1094 L698.2031,351.1094 L699.5469,347.8438 L700.875,351.1094 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="96" x="713.5" y="355.8467">IWindow.Stub</text><line style="stroke:#181818;stroke-width:0.5;" x1="685.5" x2="811.5" y1="367" y2="367"/><line style="stroke:#181818;stroke-width:0.5;" x1="685.5" x2="811.5" y1="375" y2="375"/></g><!--class w--><g id="elem_w"><rect codeline="16" fill="#F1F1F1" height="48" id="w" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="152" x="672.5" y="447"/><ellipse cx="687.5" cy="463" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M689.8438,458.6719 C688.9063,458.2344 688.3125,458.0938 687.4375,458.0938 C684.8125,458.0938 682.8125,460.1719 682.8125,462.8906 L682.8125,464.0156 C682.8125,466.5938 684.9219,468.4844 687.8125,468.4844 C689.0313,468.4844 690.1875,468.1875 690.9375,467.6406 C691.5156,467.2344 691.8438,466.7813 691.8438,466.3906 C691.8438,465.9375 691.4531,465.5469 690.9844,465.5469 C690.7656,465.5469 690.5625,465.625 690.375,465.8125 C689.9219,466.2969 689.9219,466.2969 689.7344,466.3906 C689.3125,466.6563 688.625,466.7813 687.8594,466.7813 C685.8125,466.7813 684.5156,465.6875 684.5156,463.9844 L684.5156,462.8906 C684.5156,461.1094 685.7656,459.7969 687.5,459.7969 C688.0781,459.7969 688.6875,459.9531 689.1563,460.2031 C689.6406,460.4844 689.8125,460.7031 689.9063,461.1094 C689.9688,461.5156 690,461.6406 690.1406,461.7656 C690.2813,461.9063 690.5156,462.0156 690.7344,462.0156 C691,462.0156 691.2656,461.875 691.4375,461.6563 C691.5469,461.5 691.5781,461.3125 691.5781,460.8906 L691.5781,459.4688 C691.5781,459.0313 691.5625,458.9063 691.4688,458.75 C691.3125,458.4844 691.0313,458.3438 690.7344,458.3438 C690.4375,458.3438 690.2344,458.4375 690.0156,458.75 L689.8438,458.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="120" x="701.5" y="467.8467">ViewRootImpl.W</text><line style="stroke:#181818;stroke-width:0.5;" x1="673.5" x2="823.5" y1="479" y2="479"/><line style="stroke:#181818;stroke-width:0.5;" x1="673.5" x2="823.5" y1="487" y2="487"/></g><!--class IWindow--><g id="elem_IWindow"><rect codeline="17" fill="#F1F1F1" height="48" id="IWindow" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="92" x="702.5" y="223"/><ellipse cx="717.5" cy="239" fill="#B4A7E5" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M718.4531,235.7813 L720.1719,235.7813 C720.5625,235.7813 720.75,235.75 720.875,235.6719 C721.1406,235.5156 721.2813,235.2344 721.2813,234.9375 C721.2813,234.6719 721.1719,234.4063 720.9375,234.2344 C720.7656,234.125 720.625,234.0938 720.1719,234.0938 L715.0313,234.0938 C714.5938,234.0938 714.4688,234.1094 714.3125,234.2031 C714.0625,234.3594 713.9063,234.6563 713.9063,234.9375 C713.9063,235.2188 714.0469,235.4688 714.2656,235.6406 C714.4219,235.75 714.6094,235.7813 715.0313,235.7813 L716.75,235.7813 L716.75,242.2969 L715.0313,242.2969 C714.5938,242.2969 714.4688,242.3125 714.3125,242.4219 C714.0625,242.5781 713.9063,242.8594 713.9063,243.1563 C713.9063,243.4063 714.0469,243.6719 714.2656,243.8281 C714.4219,243.9531 714.625,244 715.0313,244 L720.1719,244 C720.9219,244 721.2813,243.7188 721.2813,243.1563 C721.2813,242.875 721.1719,242.625 720.9375,242.4531 C720.7656,242.3281 720.625,242.2969 720.1719,242.2969 L718.4531,242.2969 L718.4531,235.7813 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="60" x="731.5" y="243.8467">IWindow</text><line style="stroke:#181818;stroke-width:0.5;" x1="703.5" x2="793.5" y1="255" y2="255"/><line style="stroke:#181818;stroke-width:0.5;" x1="703.5" x2="793.5" y1="263" y2="263"/></g><!--class IWindowManager--><g id="elem_IWindowManager"><rect fill="#F1F1F1" height="48" id="IWindowManager" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="153" x="7" y="447"/><ellipse cx="22" cy="463" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M24.3438,458.6719 C23.4063,458.2344 22.8125,458.0938 21.9375,458.0938 C19.3125,458.0938 17.3125,460.1719 17.3125,462.8906 L17.3125,464.0156 C17.3125,466.5938 19.4219,468.4844 22.3125,468.4844 C23.5313,468.4844 24.6875,468.1875 25.4375,467.6406 C26.0156,467.2344 26.3438,466.7813 26.3438,466.3906 C26.3438,465.9375 25.9531,465.5469 25.4844,465.5469 C25.2656,465.5469 25.0625,465.625 24.875,465.8125 C24.4219,466.2969 24.4219,466.2969 24.2344,466.3906 C23.8125,466.6563 23.125,466.7813 22.3594,466.7813 C20.3125,466.7813 19.0156,465.6875 19.0156,463.9844 L19.0156,462.8906 C19.0156,461.1094 20.2656,459.7969 22,459.7969 C22.5781,459.7969 23.1875,459.9531 23.6563,460.2031 C24.1406,460.4844 24.3125,460.7031 24.4063,461.1094 C24.4688,461.5156 24.5,461.6406 24.6406,461.7656 C24.7813,461.9063 25.0156,462.0156 25.2344,462.0156 C25.5,462.0156 25.7656,461.875 25.9375,461.6563 C26.0469,461.5 26.0781,461.3125 26.0781,460.8906 L26.0781,459.4688 C26.0781,459.0313 26.0625,458.9063 25.9688,458.75 C25.8125,458.4844 25.5313,458.3438 25.2344,458.3438 C24.9375,458.3438 24.7344,458.4375 24.5156,458.75 L24.3438,458.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="121" x="36" y="467.8467">IWindowManager</text><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="159" y1="479" y2="479"/><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="159" y1="487" y2="487"/></g><!--class Surface--><g id="elem_Surface"><rect fill="#F1F1F1" height="48" id="Surface" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="86" x="376.5" y="447"/><ellipse cx="391.5" cy="463" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M393.8438,458.6719 C392.9063,458.2344 392.3125,458.0938 391.4375,458.0938 C388.8125,458.0938 386.8125,460.1719 386.8125,462.8906 L386.8125,464.0156 C386.8125,466.5938 388.9219,468.4844 391.8125,468.4844 C393.0313,468.4844 394.1875,468.1875 394.9375,467.6406 C395.5156,467.2344 395.8438,466.7813 395.8438,466.3906 C395.8438,465.9375 395.4531,465.5469 394.9844,465.5469 C394.7656,465.5469 394.5625,465.625 394.375,465.8125 C393.9219,466.2969 393.9219,466.2969 393.7344,466.3906 C393.3125,466.6563 392.625,466.7813 391.8594,466.7813 C389.8125,466.7813 388.5156,465.6875 388.5156,463.9844 L388.5156,462.8906 C388.5156,461.1094 389.7656,459.7969 391.5,459.7969 C392.0781,459.7969 392.6875,459.9531 393.1563,460.2031 C393.6406,460.4844 393.8125,460.7031 393.9063,461.1094 C393.9688,461.5156 394,461.6406 394.1406,461.7656 C394.2813,461.9063 394.5156,462.0156 394.7344,462.0156 C395,462.0156 395.2656,461.875 395.4375,461.6563 C395.5469,461.5 395.5781,461.3125 395.5781,460.8906 L395.5781,459.4688 C395.5781,459.0313 395.5625,458.9063 395.4688,458.75 C395.3125,458.4844 395.0313,458.3438 394.7344,458.3438 C394.4375,458.3438 394.2344,458.4375 394.0156,458.75 L393.8438,458.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="54" x="405.5" y="467.8467">Surface</text><line style="stroke:#181818;stroke-width:0.5;" x1="377.5" x2="461.5" y1="479" y2="479"/><line style="stroke:#181818;stroke-width:0.5;" x1="377.5" x2="461.5" y1="487" y2="487"/></g><!--class SurfaceControl--><g id="elem_SurfaceControl"><rect fill="#F1F1F1" height="48" id="SurfaceControl" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="140" x="497.5" y="447"/><ellipse cx="512.5" cy="463" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M514.8438,458.6719 C513.9063,458.2344 513.3125,458.0938 512.4375,458.0938 C509.8125,458.0938 507.8125,460.1719 507.8125,462.8906 L507.8125,464.0156 C507.8125,466.5938 509.9219,468.4844 512.8125,468.4844 C514.0313,468.4844 515.1875,468.1875 515.9375,467.6406 C516.5156,467.2344 516.8438,466.7813 516.8438,466.3906 C516.8438,465.9375 516.4531,465.5469 515.9844,465.5469 C515.7656,465.5469 515.5625,465.625 515.375,465.8125 C514.9219,466.2969 514.9219,466.2969 514.7344,466.3906 C514.3125,466.6563 513.625,466.7813 512.8594,466.7813 C510.8125,466.7813 509.5156,465.6875 509.5156,463.9844 L509.5156,462.8906 C509.5156,461.1094 510.7656,459.7969 512.5,459.7969 C513.0781,459.7969 513.6875,459.9531 514.1563,460.2031 C514.6406,460.4844 514.8125,460.7031 514.9063,461.1094 C514.9688,461.5156 515,461.6406 515.1406,461.7656 C515.2813,461.9063 515.5156,462.0156 515.7344,462.0156 C516,462.0156 516.2656,461.875 516.4375,461.6563 C516.5469,461.5 516.5781,461.3125 516.5781,460.8906 L516.5781,459.4688 C516.5781,459.0313 516.5625,458.9063 516.4688,458.75 C516.3125,458.4844 516.0313,458.3438 515.7344,458.3438 C515.4375,458.3438 515.2344,458.4375 515.0156,458.75 L514.8438,458.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="108" x="526.5" y="467.8467">SurfaceControl</text><line style="stroke:#181818;stroke-width:0.5;" x1="498.5" x2="636.5" y1="479" y2="479"/><line style="stroke:#181818;stroke-width:0.5;" x1="498.5" x2="636.5" y1="487" y2="487"/></g><!--reverse link Activity to Window--><g id="link_Activity_Window"><path codeline="4" d="M265.703,31 C277.297,31 276.891,31 288.485,31 " fill="none" id="Activity-backto-Window" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="253.703,31,259.703,35,265.703,31,259.703,27,253.703,31" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link Window to PhoneWindow--><g id="link_Window_PhoneWindow"><path codeline="5" d="M363.3864,68.7853 C378.2124,86.4433 387.026,96.941 401.919,114.678 " fill="none" id="Window-backto-PhoneWindow" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="351.812,55,358.7913,72.6434,367.9815,64.9271,351.812,55" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link Window to WindowManager--><g id="link_Window_WindowManager"><path codeline="6" d="M305.7401,64.233 C291.0811,81.891 278.587,96.941 263.861,114.678 " fill="none" id="Window-backto-WindowManager" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="313.405,55,306.4949,57.0615,305.7401,64.233,312.6502,62.1715,313.405,55" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link WindowManager to WindowManagerImpl--><g id="link_WindowManager_WindowManagerImpl"><path codeline="7" d="M244.5,181 C244.5,198.658 244.5,204.941 244.5,222.678 " fill="none" id="WindowManager-backto-WindowManagerImpl" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="244.5,163,238.5,181,250.5,181,244.5,163" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link WindowManagerImpl to WindowManagerGlobal--><g id="link_WindowManagerImpl_WindowManagerGlobal"><path codeline="9" d="M244.5,283.06 C244.5,300.447 244.5,312.353 244.5,330.696 " fill="none" id="WindowManagerImpl-backto-WindowManagerGlobal" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="244.5,271.06,240.5,277.06,244.5,283.06,248.5,277.06,244.5,271.06" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link ViewParent to ViewRootImpl--><g id="link_ViewParent_ViewRootImpl"><path codeline="11" d="M443.5,289.06 C443.5,307.833 443.5,316.205 443.5,334.971 " fill="none" id="ViewParent-backto-ViewRootImpl" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="443.5,271.06,437.5,289.06,449.5,289.06,443.5,271.06" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link ViewRootImpl to IWindowSession--><g id="link_ViewRootImpl_IWindowSession"><path codeline="13" d="M396.6543,389.446 C366.7873,408.2193 334.992,428.2052 305.137,446.9708 " fill="none" id="ViewRootImpl-backto-IWindowSession" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="406.814,383.06,399.6055,382.8664,396.6543,389.446,403.8628,389.6396,406.814,383.06" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link IWindow to IWindow_Stub--><g id="link_IWindow_IWindow_Stub"><path codeline="18" d="M748.5,289.06 C748.5,307.833 748.5,316.205 748.5,334.971 " fill="none" id="IWindow-backto-IWindow_Stub" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:7.0,7.0;"/><polygon fill="none" points="748.5,271.06,742.5,289.06,754.5,289.06,748.5,271.06" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link IWindow_Stub to w--><g id="link_IWindow_Stub_w"><path codeline="19" d="M748.5,401.06 C748.5,419.8333 748.5,428.2052 748.5,446.9708 " fill="none" id="IWindow_Stub-backto-w" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="748.5,383.06,742.5,401.06,754.5,401.06,748.5,383.06" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link ViewRootImpl to w--><g id="link_ViewRootImpl_w"><path codeline="20" d="M518.7263,387.1311 C570.7803,405.9044 632.614,428.2052 684.646,446.9708 " fill="none" id="ViewRootImpl-backto-w" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="507.438,383.06,511.7251,388.8583,518.7263,387.1311,514.4392,381.3328,507.438,383.06" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link WindowManagerGlobal to ViewRootImpl--><g id="link_WindowManagerGlobal_ViewRootImpl"><path codeline="22" d="M354.057,359 C365.68,359 365.304,359 376.928,359 " fill="none" id="WindowManagerGlobal-backto-ViewRootImpl" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="342.057,359,348.057,363,354.057,359,348.057,355,342.057,359" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="8" x="350.1498" y="355.4639">1</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="8" x="361.2092" y="355.2538">n</text></g><!--reverse link WindowManagerGlobal to IWindowManager--><g id="link_WindowManagerGlobal_IWindowManager"><path codeline="23" d="M194.7938,393.9606 C167.9758,412.2836 142.887,429.4249 117.398,446.8398 " fill="none" id="WindowManagerGlobal-backto-IWindowManager" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="204.702,387.191,197.4914,387.2731,194.7938,393.9606,202.0044,393.8785,204.702,387.191" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link WindowManagerGlobal to IWindowSession--><g id="link_WindowManagerGlobal_IWindowSession"><path codeline="24" d="M252.9905,398.9153 C256.9875,417.2383 259.647,429.4249 263.447,446.8398 " fill="none" id="WindowManagerGlobal-backto-IWindowSession" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="250.433,387.191,247.8037,393.9057,252.9905,398.9153,255.6199,392.2006,250.433,387.191" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link ViewRootImpl to Surface--><g id="link_ViewRootImpl_Surface"><path codeline="26" d="M435.911,394.7842 C431.815,413.5575 428.619,428.2052 424.525,446.9708 " fill="none" id="ViewRootImpl-backto-Surface" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="438.469,383.06,433.2819,388.0694,435.911,394.7842,441.0981,389.7748,438.469,383.06" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link ViewRootImpl to SurfaceControl--><g id="link_ViewRootImpl_SurfaceControl"><path codeline="27" d="M478.4712,391.0231 C499.6352,409.7964 520.386,428.2052 541.54,446.9708 " fill="none" id="ViewRootImpl-backto-SurfaceControl" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="469.494,383.06,471.3282,390.0339,478.4712,391.0231,476.6369,384.0492,469.494,383.06" style="stroke:#181818;stroke-width:1.0;"/></g><!--SRC=[TL71QiCm3BtxAuHtw5QMq9rw2OKjq973e2om7eUIUOd1iuljDWpsyLjYPtNgz6JhwUb9Ubh04ngMepoXWUmdIS3z2PUMwK-i6Uov_53T2qfic2PO6Qknjb0BDCOdoMDj-OdRRrWc8-GUfxbhbMHJV9aa5ygJoDLDeEBh84ZOrUFFGbKe8ClWjho_sMxNwzNg3aek6y6iah3Pa4WdRkzKWhNVEEjsg9cqvFnrO_Nngr9scEXSKJZ1aXd3bIGXQ-XtaLz0nCXRfPbgD1xQq6hgAzFI7YiAVvVom7iFU4zeg9Rk1reNJqUA_yEawLGd3DoYNRn4HyYS-_I1zhUdaaxTcUFsCcFdsUFFy4RJue7Aux3VrKIkfDLA_080]--></g></svg>

<h2 id="IWindowManager"><a href="#IWindowManager" class="headerlink" title="IWindowManager"></a>IWindowManager</h2><p>IWindowManager在<code>IWindowManager.aidl</code>文件中定义，是<code>WindowManagerService</code>的对外接口。</p>
<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentstyletype="text/css" height="278px" preserveAspectRatio="none" style="width:464px;height:278px;background:#FFFFFF;" version="1.1" viewBox="0 0 464 278" width="464px" zoomAndPan="magnify"><defs/><g><!--class IWindowManager--><g id="elem_IWindowManager"><rect codeline="1" fill="#F1F1F1" height="48" id="IWindowManager" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="155" x="302.5" y="7"/><ellipse cx="317.5" cy="23" fill="#B4A7E5" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M318.4531,19.7813 L320.1719,19.7813 C320.5625,19.7813 320.75,19.75 320.875,19.6719 C321.1406,19.5156 321.2813,19.2344 321.2813,18.9375 C321.2813,18.6719 321.1719,18.4063 320.9375,18.2344 C320.7656,18.125 320.625,18.0938 320.1719,18.0938 L315.0313,18.0938 C314.5938,18.0938 314.4688,18.1094 314.3125,18.2031 C314.0625,18.3594 313.9063,18.6563 313.9063,18.9375 C313.9063,19.2188 314.0469,19.4688 314.2656,19.6406 C314.4219,19.75 314.6094,19.7813 315.0313,19.7813 L316.75,19.7813 L316.75,26.2969 L315.0313,26.2969 C314.5938,26.2969 314.4688,26.3125 314.3125,26.4219 C314.0625,26.5781 313.9063,26.8594 313.9063,27.1563 C313.9063,27.4063 314.0469,27.6719 314.2656,27.8281 C314.4219,27.9531 314.625,28 315.0313,28 L320.1719,28 C320.9219,28 321.2813,27.7188 321.2813,27.1563 C321.2813,26.875 321.1719,26.625 320.9375,26.4531 C320.7656,26.3281 320.625,26.2969 320.1719,26.2969 L318.4531,26.2969 L318.4531,19.7813 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="123" x="331.5" y="27.8467">IWindowManager</text><line style="stroke:#181818;stroke-width:0.5;" x1="303.5" x2="456.5" y1="39" y2="39"/><line style="stroke:#181818;stroke-width:0.5;" x1="303.5" x2="456.5" y1="47" y2="47"/></g><!--class stub--><g id="elem_stub"><rect codeline="2" fill="#F1F1F1" height="48" id="stub" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="191" x="245.5" y="115"/><ellipse cx="260.5" cy="131" fill="#A9DCDF" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M262.5781,132.8125 L262.9688,133.7969 L262.5781,133.7969 C262.125,133.7969 262.0156,133.8125 261.8594,133.9219 C261.6094,134.0781 261.4531,134.3594 261.4531,134.6563 C261.4531,134.9219 261.5938,135.1719 261.8125,135.3281 C261.9531,135.4531 262.1563,135.5 262.5781,135.5 L264.9375,135.5 C265.2969,135.5 265.5156,135.4688 265.6563,135.375 C265.9063,135.2344 266.0625,134.9375 266.0625,134.6563 C266.0625,134.375 265.9219,134.125 265.7031,133.9688 C265.5313,133.8281 265.375,133.7969 264.9063,133.7969 L261.5156,125.5938 L257.8438,125.5938 C257.3906,125.5938 257.2656,125.6094 257.1094,125.7031 C256.8594,125.875 256.7031,126.1563 256.7031,126.4375 C256.7031,126.7188 256.8438,126.9688 257.0625,127.1406 C257.2344,127.25 257.4063,127.2813 257.8438,127.2813 L258.9219,127.2813 L256.2813,133.7969 C255.8594,133.7969 255.7031,133.8125 255.5469,133.9219 C255.2969,134.0781 255.1406,134.3594 255.1406,134.6563 C255.1406,135.2188 255.5156,135.5 256.2656,135.5 L258.5313,135.5 C258.8906,135.5 259.1094,135.4688 259.2344,135.375 C259.5,135.2344 259.6406,134.9375 259.6406,134.6563 C259.6406,134.375 259.5156,134.125 259.2969,133.9531 C259.125,133.8281 258.9844,133.7969 258.5313,133.7969 L258.1406,133.7969 L258.5313,132.8125 L262.5781,132.8125 Z M261.875,131.1094 L259.2031,131.1094 L260.5469,127.8438 L261.875,131.1094 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="159" x="274.5" y="135.8467">IWindowManager.Stub</text><line style="stroke:#181818;stroke-width:0.5;" x1="246.5" x2="435.5" y1="147" y2="147"/><line style="stroke:#181818;stroke-width:0.5;" x1="246.5" x2="435.5" y1="155" y2="155"/></g><!--class Binder--><g id="elem_Binder"><rect fill="#F1F1F1" height="48" id="Binder" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="79" x="188.5" y="7"/><ellipse cx="203.5" cy="23" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M205.8438,18.6719 C204.9063,18.2344 204.3125,18.0938 203.4375,18.0938 C200.8125,18.0938 198.8125,20.1719 198.8125,22.8906 L198.8125,24.0156 C198.8125,26.5938 200.9219,28.4844 203.8125,28.4844 C205.0313,28.4844 206.1875,28.1875 206.9375,27.6406 C207.5156,27.2344 207.8438,26.7813 207.8438,26.3906 C207.8438,25.9375 207.4531,25.5469 206.9844,25.5469 C206.7656,25.5469 206.5625,25.625 206.375,25.8125 C205.9219,26.2969 205.9219,26.2969 205.7344,26.3906 C205.3125,26.6563 204.625,26.7813 203.8594,26.7813 C201.8125,26.7813 200.5156,25.6875 200.5156,23.9844 L200.5156,22.8906 C200.5156,21.1094 201.7656,19.7969 203.5,19.7969 C204.0781,19.7969 204.6875,19.9531 205.1563,20.2031 C205.6406,20.4844 205.8125,20.7031 205.9063,21.1094 C205.9688,21.5156 206,21.6406 206.1406,21.7656 C206.2813,21.9063 206.5156,22.0156 206.7344,22.0156 C207,22.0156 207.2656,21.875 207.4375,21.6563 C207.5469,21.5 207.5781,21.3125 207.5781,20.8906 L207.5781,19.4688 C207.5781,19.0313 207.5625,18.9063 207.4688,18.75 C207.3125,18.4844 207.0313,18.3438 206.7344,18.3438 C206.4375,18.3438 206.2344,18.4375 206.0156,18.75 L205.8438,18.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="47" x="217.5" y="27.8467">Binder</text><line style="stroke:#181818;stroke-width:0.5;" x1="189.5" x2="266.5" y1="39" y2="39"/><line style="stroke:#181818;stroke-width:0.5;" x1="189.5" x2="266.5" y1="47" y2="47"/></g><!--class WindowManagerService--><g id="elem_WindowManagerService"><rect fill="#F1F1F1" height="48" id="WindowManagerService" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="202" x="229" y="223"/><ellipse cx="244" cy="239" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M246.3438,234.6719 C245.4063,234.2344 244.8125,234.0938 243.9375,234.0938 C241.3125,234.0938 239.3125,236.1719 239.3125,238.8906 L239.3125,240.0156 C239.3125,242.5938 241.4219,244.4844 244.3125,244.4844 C245.5313,244.4844 246.6875,244.1875 247.4375,243.6406 C248.0156,243.2344 248.3438,242.7813 248.3438,242.3906 C248.3438,241.9375 247.9531,241.5469 247.4844,241.5469 C247.2656,241.5469 247.0625,241.625 246.875,241.8125 C246.4219,242.2969 246.4219,242.2969 246.2344,242.3906 C245.8125,242.6563 245.125,242.7813 244.3594,242.7813 C242.3125,242.7813 241.0156,241.6875 241.0156,239.9844 L241.0156,238.8906 C241.0156,237.1094 242.2656,235.7969 244,235.7969 C244.5781,235.7969 245.1875,235.9531 245.6563,236.2031 C246.1406,236.4844 246.3125,236.7031 246.4063,237.1094 C246.4688,237.5156 246.5,237.6406 246.6406,237.7656 C246.7813,237.9063 247.0156,238.0156 247.2344,238.0156 C247.5,238.0156 247.7656,237.875 247.9375,237.6563 C248.0469,237.5 248.0781,237.3125 248.0781,236.8906 L248.0781,235.4688 C248.0781,235.0313 248.0625,234.9063 247.9688,234.75 C247.8125,234.4844 247.5313,234.3438 247.2344,234.3438 C246.9375,234.3438 246.7344,234.4375 246.5156,234.75 L246.3438,234.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="170" x="258" y="243.8467">WindowManagerService</text><line style="stroke:#181818;stroke-width:0.5;" x1="230" x2="430" y1="255" y2="255"/><line style="stroke:#181818;stroke-width:0.5;" x1="230" x2="430" y1="263" y2="263"/></g><!--class IWindowSession--><g id="elem_IWindowSession"><rect codeline="7" fill="#F1F1F1" height="48" id="IWindowSession" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="146" x="7" y="7"/><ellipse cx="22" cy="23" fill="#B4A7E5" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M22.9531,19.7813 L24.6719,19.7813 C25.0625,19.7813 25.25,19.75 25.375,19.6719 C25.6406,19.5156 25.7813,19.2344 25.7813,18.9375 C25.7813,18.6719 25.6719,18.4063 25.4375,18.2344 C25.2656,18.125 25.125,18.0938 24.6719,18.0938 L19.5313,18.0938 C19.0938,18.0938 18.9688,18.1094 18.8125,18.2031 C18.5625,18.3594 18.4063,18.6563 18.4063,18.9375 C18.4063,19.2188 18.5469,19.4688 18.7656,19.6406 C18.9219,19.75 19.1094,19.7813 19.5313,19.7813 L21.25,19.7813 L21.25,26.2969 L19.5313,26.2969 C19.0938,26.2969 18.9688,26.3125 18.8125,26.4219 C18.5625,26.5781 18.4063,26.8594 18.4063,27.1563 C18.4063,27.4063 18.5469,27.6719 18.7656,27.8281 C18.9219,27.9531 19.125,28 19.5313,28 L24.6719,28 C25.4219,28 25.7813,27.7188 25.7813,27.1563 C25.7813,26.875 25.6719,26.625 25.4375,26.4531 C25.2656,26.3281 25.125,26.2969 24.6719,26.2969 L22.9531,26.2969 L22.9531,19.7813 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="114" x="36" y="27.8467">IWindowSession</text><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="152" y1="39" y2="39"/><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="152" y1="47" y2="47"/></g><!--class SessionStub--><g id="elem_SessionStub"><rect codeline="8" fill="#F1F1F1" height="48" id="SessionStub" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="182" x="28" y="115"/><ellipse cx="43" cy="131" fill="#A9DCDF" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M45.0781,132.8125 L45.4688,133.7969 L45.0781,133.7969 C44.625,133.7969 44.5156,133.8125 44.3594,133.9219 C44.1094,134.0781 43.9531,134.3594 43.9531,134.6563 C43.9531,134.9219 44.0938,135.1719 44.3125,135.3281 C44.4531,135.4531 44.6563,135.5 45.0781,135.5 L47.4375,135.5 C47.7969,135.5 48.0156,135.4688 48.1563,135.375 C48.4063,135.2344 48.5625,134.9375 48.5625,134.6563 C48.5625,134.375 48.4219,134.125 48.2031,133.9688 C48.0313,133.8281 47.875,133.7969 47.4063,133.7969 L44.0156,125.5938 L40.3438,125.5938 C39.8906,125.5938 39.7656,125.6094 39.6094,125.7031 C39.3594,125.875 39.2031,126.1563 39.2031,126.4375 C39.2031,126.7188 39.3438,126.9688 39.5625,127.1406 C39.7344,127.25 39.9063,127.2813 40.3438,127.2813 L41.4219,127.2813 L38.7813,133.7969 C38.3594,133.7969 38.2031,133.8125 38.0469,133.9219 C37.7969,134.0781 37.6406,134.3594 37.6406,134.6563 C37.6406,135.2188 38.0156,135.5 38.7656,135.5 L41.0313,135.5 C41.3906,135.5 41.6094,135.4688 41.7344,135.375 C42,135.2344 42.1406,134.9375 42.1406,134.6563 C42.1406,134.375 42.0156,134.125 41.7969,133.9531 C41.625,133.8281 41.4844,133.7969 41.0313,133.7969 L40.6406,133.7969 L41.0313,132.8125 L45.0781,132.8125 Z M44.375,131.1094 L41.7031,131.1094 L43.0469,127.8438 L44.375,131.1094 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="150" x="57" y="135.8467">IWindowSession.Stub</text><line style="stroke:#181818;stroke-width:0.5;" x1="29" x2="209" y1="147" y2="147"/><line style="stroke:#181818;stroke-width:0.5;" x1="29" x2="209" y1="155" y2="155"/></g><!--class Session--><g id="elem_Session"><rect fill="#F1F1F1" height="48" id="Session" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="86" x="97" y="223"/><ellipse cx="112" cy="239" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M114.3438,234.6719 C113.4063,234.2344 112.8125,234.0938 111.9375,234.0938 C109.3125,234.0938 107.3125,236.1719 107.3125,238.8906 L107.3125,240.0156 C107.3125,242.5938 109.4219,244.4844 112.3125,244.4844 C113.5313,244.4844 114.6875,244.1875 115.4375,243.6406 C116.0156,243.2344 116.3438,242.7813 116.3438,242.3906 C116.3438,241.9375 115.9531,241.5469 115.4844,241.5469 C115.2656,241.5469 115.0625,241.625 114.875,241.8125 C114.4219,242.2969 114.4219,242.2969 114.2344,242.3906 C113.8125,242.6563 113.125,242.7813 112.3594,242.7813 C110.3125,242.7813 109.0156,241.6875 109.0156,239.9844 L109.0156,238.8906 C109.0156,237.1094 110.2656,235.7969 112,235.7969 C112.5781,235.7969 113.1875,235.9531 113.6563,236.2031 C114.1406,236.4844 114.3125,236.7031 114.4063,237.1094 C114.4688,237.5156 114.5,237.6406 114.6406,237.7656 C114.7813,237.9063 115.0156,238.0156 115.2344,238.0156 C115.5,238.0156 115.7656,237.875 115.9375,237.6563 C116.0469,237.5 116.0781,237.3125 116.0781,236.8906 L116.0781,235.4688 C116.0781,235.0313 116.0625,234.9063 115.9688,234.75 C115.8125,234.4844 115.5313,234.3438 115.2344,234.3438 C114.9375,234.3438 114.7344,234.4375 114.5156,234.75 L114.3438,234.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="54" x="126" y="243.8467">Session</text><line style="stroke:#181818;stroke-width:0.5;" x1="98" x2="182" y1="255" y2="255"/><line style="stroke:#181818;stroke-width:0.5;" x1="98" x2="182" y1="263" y2="263"/></g><!--reverse link IWindowManager to stub--><g id="link_IWindowManager_stub"><path codeline="3" d="M365.3225,71.8928 C358.8255,89.5508 356.107,96.941 349.581,114.678 " fill="none" id="IWindowManager-backto-stub" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="371.538,55,359.6916,69.821,370.9535,73.9647,371.538,55" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link Binder to stub--><g id="link_Binder_stub"><path codeline="4" d="M265.647,67.3148 C284.471,84.9728 297.229,96.941 316.138,114.678 " fill="none" id="Binder-backto-stub" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="252.519,55,261.5421,71.6908,269.752,62.9388,252.519,55" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link stub to WindowManagerService--><g id="link_stub_WindowManagerService"><path codeline="5" d="M336.7555,180.9039 C334.9235,198.5623 334.261,204.9408 332.42,222.6784 " fill="none" id="stub-backto-WindowManagerService" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="338.613,163,330.7876,180.2847,342.7235,181.5231,338.613,163" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link SessionStub to Session--><g id="link_SessionStub_Session"><path codeline="9" d="M127.0547,180.6569 C130.5527,198.3153 131.866,204.9408 135.38,222.6784 " fill="none" id="SessionStub-backto-Session" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="123.557,163,121.1691,181.8228,132.9403,179.491,123.557,163" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link Binder to SessionStub--><g id="link_Binder_SessionStub"><path codeline="10" d="M191.4447,67.549 C173.2867,85.207 161.221,96.941 142.982,114.678 " fill="none" id="Binder-backto-SessionStub" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="204.349,55,187.2616,63.2476,195.6277,71.8505,204.349,55" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link Session to WindowManagerService--><g id="link_Session_WindowManagerService"><path codeline="11" d="M195.047,247 C210.354,247 213.662,247 228.97,247 " fill="none" id="Session-backto-WindowManagerService" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="183.047,247,189.047,251,195.047,247,189.047,243,183.047,247" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link IWindowSession to SessionStub--><g id="link_IWindowSession_SessionStub"><path codeline="12" d="M94.6777,71.8929 C101.1745,89.5509 103.8933,96.941 110.419,114.678 " fill="none" id="IWindowSession-backto-SessionStub" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="88.4624,55,89.0467,73.9647,100.3087,69.8211,88.4624,55" style="stroke:#181818;stroke-width:1.0;"/></g><!--SRC=[oymhIIrAIqnELV0CpynBoI_tJSnBJ4yjuafCAYufIamkKL12bT0BBYbDKb98B5Oe1ZAuK2KLR6fqTI4IJa1n504G0U6YQ0bEBIhBJ4xbuif4TqbmQd5nPduUfakW4WYNG0L0V2uaDiGsc3783iAYGK4BXyDGBSNG3m00]--></g></svg>

<h2 id="IWindowSession"><a href="#IWindowSession" class="headerlink" title="IWindowSession"></a>IWindowSession</h2><p>每个app都会有一个Window Session用于与window manager进行交互。<code>IWindowSession</code>是通过aidl定义的binder接口，app通过IWindowSession与WMS进行交互。</p>
<pre class="mermaid">

zenuml
new ViewRootImpl() {
    WindowManagerGlobal.getWindowSession {
        &#x2F;&#x2F;sWindowSession是WindowManagerGlobal的静态类变量
        &#x2F;&#x2F;如果sWindowSession为空就通过WMS.openSession来打开一个
        if (sWindowSession &#x3D;&#x3D; null) {
            WindowManagerService.openSession {
                new Session()
            }
        }
        return sWindowSession
    }
}
</pre>

<h2 id="addWindow把IWindow加入到WMS"><a href="#addWindow把IWindow加入到WMS" class="headerlink" title="addWindow把IWindow加入到WMS"></a>addWindow把<code>IWindow</code>加入到WMS</h2><p>IWindow是一个binder接口，这个binder的service端是app，实现类是<code>ViewRootImpl.W</code>，client端是WMS。WMS会通过IWindow这个binder接口来通知app window相关的事件。先看下addWindow的调用时序：</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/90f60c72.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/936e646.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/936e646.html" class="post-title-link" itemprop="url">Android Jni开发指南</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-10-19 16:34:16" itemprop="dateCreated datePublished" datetime="2023-10-19T16:34:16+08:00">2023-10-19</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2024-01-09 11:07:10" itemprop="dateModified" datetime="2024-01-09T11:07:10+08:00">2024-01-09</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="现有项目添加C-C-源码"><a href="#现有项目添加C-C-源码" class="headerlink" title="现有项目添加C/C++源码"></a>现有项目添加C/C++源码</h2><p>如果现有项目还不支持C/C++，则可以通过如下步骤来加入C/C++</p>
<p><img src="/images/Android/Android-Jni%E6%8C%87%E5%8D%97_2023-10-19-19-01-13.png" alt="Add C++ to Module"></p>
<p>然后按照步骤操作即可。添加完成后打开<code>app\src\main\cpp\CMakeLists.txt</code>文件，修改项目名称</p>
<h2 id="Java-Kotlin代码声明native函数"><a href="#Java-Kotlin代码声明native函数" class="headerlink" title="Java/Kotlin代码声明native函数"></a>Java/Kotlin代码声明native函数</h2><p>我们在<code>me.rjy.android.demo.MainActivity</code>中定义一个native函数，并加载native库。</p>
<p>Java代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MainActivity</span> <span class="keyword">extends</span> <span class="title class_">AppCompatActivity</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">native</span> String <span class="title function_">stringFromJNI</span><span class="params">()</span>;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">static</span> &#123;</span><br><span class="line">        System.loadLibrary(<span class="string">&quot;demo&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>Kotlin代码：</p>
<figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">MainActivity</span> : <span class="type">ComponentActivity</span>() &#123;</span><br><span class="line">    <span class="keyword">external</span> <span class="function"><span class="keyword">fun</span> <span class="title">stringFromJNI</span><span class="params">()</span></span>: String</span><br><span class="line"></span><br><span class="line">    <span class="keyword">companion</span> <span class="keyword">object</span> &#123;</span><br><span class="line">        <span class="keyword">init</span> &#123;</span><br><span class="line">            System.loadLibrary(<span class="string">&quot;demo&quot;</span>)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/936e646.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/93b40782.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/93b40782.html" class="post-title-link" itemprop="url">Activity启动流程 (Android13)</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-10-07 11:11:56" itemprop="dateCreated datePublished" datetime="2023-10-07T11:11:56+08:00">2023-10-07</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2024-01-05 19:09:25" itemprop="dateModified" datetime="2024-01-05T19:09:25+08:00">2024-01-05</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <!-- toc -->

<p>本文以时序图的形式来展示activity的启动过程，相比于贴源码会更加直观。本文的讲解的流程是基于<code>MainActivity</code>使用standard模式启动<code>SecondActivity</code>，且两个Activity都在同一个应用中，最后的部分也会讲解一下进程的启动。</p>
<h2 id="第一阶段：执行startActivity"><a href="#第一阶段：执行startActivity" class="headerlink" title="第一阶段：执行startActivity"></a>第一阶段：执行startActivity</h2><pre class="mermaid">

zenuml
group App {
    &lt;&lt;App&gt;&gt; act as Activity
    &lt;&lt;App&gt;&gt; ins as Instrumentation
}
group AMS {
    &lt;&lt;AMS&gt;&gt; atms as ActivityTaskManagerService #F0F8FF
    ActivityStarter #F0F8FF
}
act.startActivity {
    act.startActivityForResult {
        ins.execStartActivity {
            atms.startActivity {
                atms.startActivityAsUser {
                    &#x2F;&#x2F;没有缓存则创建
                    new ActivityStarter()
                    ActivityStarter.&quot;① execute&quot;
                }
            }
        }
    }
}
</pre>

<pre class="mermaid">

zenuml
&lt;&lt;AMS&gt;&gt; ActivityStarter #F0F8FF
ActivityStarter.&quot;① execute&quot; {
    executeRequest {
        new ActivityRecord()
        startActivityUnchecked {
            startActivityInner {
                Task.addChild
                Task.startActivityLocked
                RootWindowContainer.resumeFocusedTasksTopActivities {
                    Task.resumeTopActivityUncheckedLocked {
                        resumeTopActivityInnerLocked {
                            TaskFragment.resumeTopActivity {
                                &#x2F;&#x2F;pause当前activity
                                &quot;② startPausing()&quot;
                                if (! isProcessRunning) {
                                    ActivityTaskManagerService.startProcessAsync
                                }
                            }
                        }
                    }
                }
            }
            handleStartResult
            postStartActivityProcessing
        }
    }
}
</pre>

<h2 id="第二阶段：pause当前activity"><a href="#第二阶段：pause当前activity" class="headerlink" title="第二阶段：pause当前activity"></a>第二阶段：pause当前activity</h2><p>启动<code>SecondActivity</code>之前会先执行<code>MainActivity</code>的<strong>pause</strong>操作：</p>
<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentstyletype="text/css" height="955px" preserveAspectRatio="none" style="width:1004px;height:955px;background:#FFFFFF;" version="1.1" viewBox="0 0 1004 955" width="1004px" zoomAndPan="magnify"><defs/><g><rect fill="#F0F8FF" height="943.9141" style="stroke:#181818;stroke-width:0.5;" width="470" x="75.5" y="6"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="32" x="292" y="18.0669">AMS</text><rect fill="#F0F0F0" height="943.9141" style="stroke:#181818;stroke-width:0.5;" width="450.5" x="547.5" y="6"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="30" x="755.25" y="18.0669">APP</text><rect fill="#FFFFFF" height="274.0625" style="stroke:#181818;stroke-width:1.0;" width="10" x="133" y="87.5625"/><rect fill="#FFBBBB" height="236.9297" style="stroke:#181818;stroke-width:1.0;" width="10" x="138" y="124.6953"/><rect fill="#FFFFFF" height="137.5313" style="stroke:#181818;stroke-width:1.0;" width="10" x="143" y="224.0938"/><rect fill="#FFFFFF" height="74.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="335" y="331.625"/><rect fill="#FFFFFF" height="68.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="476" y="838.4844"/><rect fill="#FFFFFF" height="85.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="606.5" y="443.0234"/><rect fill="#FFFFFF" height="34.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="606.5" y="572.4219"/><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="606.5" y="692.9531"/><rect fill="#FFFFFF" height="261.9297" style="stroke:#181818;stroke-width:1.0;" width="10" x="787.5" y="606.5547"/><rect fill="#FFFFFF" height="63.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="792.5" y="658.8203"/><rect fill="#FFFFFF" height="94.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="792.5" y="774.3516"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="137.5" x2="137.5" y1="56.4297" y2="915.6172"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="339.5" x2="339.5" y1="56.4297" y2="915.6172"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="480.5" x2="480.5" y1="56.4297" y2="915.6172"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="611.5" x2="611.5" y1="56.4297" y2="915.6172"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="792.5" x2="792.5" y1="56.4297" y2="915.6172"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="942" x2="942" y1="56.4297" y2="915.6172"/><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="117" x="79.5" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="103" x="86.5" y="45.1279">TaskFragment</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="117" x="79.5" y="914.6172"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="103" x="86.5" y="934.6123">TaskFragment</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="141" x="269.5" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="127" x="276.5" y="45.1279">ClientTransaction</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="141" x="269.5" y="914.6172"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="127" x="276.5" y="934.6123">ClientTransaction</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="121" x="420.5" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="107" x="427.5" y="45.1279">ActivityRecord</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="121" x="420.5" y="914.6172"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="107" x="427.5" y="934.6123">ActivityRecord</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="120" x="551.5" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="106" x="558.5" y="45.1279">ActivityThread</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="120" x="551.5" y="914.6172"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="106" x="558.5" y="934.6123">ActivityThread</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="162" x="711.5" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="148" x="718.5" y="45.1279">TransactionExecutor</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="162" x="711.5" y="914.6172"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="148" x="718.5" y="934.6123">TransactionExecutor</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="103" x="891" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="89" x="898" y="45.1279">MainActivity</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="103" x="891" y="914.6172"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="89" x="898" y="934.6123">MainActivity</text><rect fill="#FFFFFF" height="274.0625" style="stroke:#181818;stroke-width:1.0;" width="10" x="133" y="87.5625"/><rect fill="#FFBBBB" height="236.9297" style="stroke:#181818;stroke-width:1.0;" width="10" x="138" y="124.6953"/><rect fill="#FFFFFF" height="137.5313" style="stroke:#181818;stroke-width:1.0;" width="10" x="143" y="224.0938"/><rect fill="#FFFFFF" height="74.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="335" y="331.625"/><rect fill="#FFFFFF" height="68.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="476" y="838.4844"/><rect fill="#FFFFFF" height="85.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="606.5" y="443.0234"/><rect fill="#FFFFFF" height="34.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="606.5" y="572.4219"/><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="606.5" y="692.9531"/><rect fill="#FFFFFF" height="261.9297" style="stroke:#181818;stroke-width:1.0;" width="10" x="787.5" y="606.5547"/><rect fill="#FFFFFF" height="63.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="792.5" y="658.8203"/><rect fill="#FFFFFF" height="94.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="792.5" y="774.3516"/><ellipse cx="7.5" cy="86.8125" fill="none" rx="4" ry="4" style="stroke:#181818;stroke-width:1.5;"/><polygon fill="#181818" points="121,83.5625,131,87.5625,121,91.5625,125,87.5625" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="12" x2="127" y1="87.5625" y2="87.5625"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="106" x="10" y="82.4966">&#9313; startPausing()</text><line style="stroke:#181818;stroke-width:1.0;" x1="143" x2="190" y1="111.6953" y2="111.6953"/><line style="stroke:#181818;stroke-width:1.0;" x1="190" x2="190" y1="111.6953" y2="124.6953"/><line style="stroke:#181818;stroke-width:1.0;" x1="149" x2="190" y1="124.6953" y2="124.6953"/><polygon fill="#181818" points="159,120.6953,149,124.6953,159,128.6953,155,124.6953" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="144" x="155" y="106.6294">schedulePauseActivity</text><line style="stroke:#181818;stroke-width:1.0;" x1="148" x2="190" y1="158.8281" y2="158.8281"/><line style="stroke:#181818;stroke-width:1.0;" x1="190" x2="190" y1="158.8281" y2="171.8281"/><line style="stroke:#181818;stroke-width:1.0;" x1="149" x2="190" y1="171.8281" y2="171.8281"/><polygon fill="#181818" points="159,167.8281,149,171.8281,159,175.8281,155,171.8281" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="170" x="155" y="153.7622">PauseActivityItem.obtain()</text><line style="stroke:#181818;stroke-width:1.0;" x1="148" x2="195" y1="211.0938" y2="211.0938"/><line style="stroke:#181818;stroke-width:1.0;" x1="195" x2="195" y1="211.0938" y2="224.0938"/><line style="stroke:#181818;stroke-width:1.0;" x1="154" x2="195" y1="224.0938" y2="224.0938"/><polygon fill="#181818" points="164,220.0938,154,224.0938,164,228.0938,160,224.0938" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="151" x="160" y="190.895">ClientLifecycleManager.</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="132" x="164" y="206.0278">scheduleTransaction</text><polygon fill="#181818" points="328,254.2266,338,258.2266,328,262.2266,332,258.2266" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="153" x2="334" y1="258.2266" y2="258.2266"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="40" x="283" y="253.1606">obtain</text><polygon fill="#181818" points="328,298.4922,338,302.4922,328,306.4922,332,302.4922" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="153" x2="334" y1="302.4922" y2="302.4922"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="163" x="160" y="282.2935">setLifecycleStateRequest</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="126" x="160" y="297.4263">(PauseActivityItem)</text><polygon fill="#181818" points="323,327.625,333,331.625,323,335.625,327,331.625" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="153" x2="329" y1="331.625" y2="331.625"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="67" x="251" y="326.5591">schedule()</text><polygon fill="#181818" points="599.5,401.8906,609.5,405.8906,599.5,409.8906,603.5,405.8906" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="340" x2="605.5" y1="405.8906" y2="405.8906"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="136" x="429.5" y="385.6919">[ApplicationThread]&#8594;</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="165" x="429.5" y="400.8247">scheduleTransaction(this)</text><line style="stroke:#181818;stroke-width:1.0;" x1="616.5" x2="658.5" y1="435.0234" y2="435.0234"/><line style="stroke:#181818;stroke-width:1.0;" x1="658.5" x2="658.5" y1="435.0234" y2="448.0234"/><line style="stroke:#181818;stroke-width:1.0;" x1="617.5" x2="658.5" y1="448.0234" y2="448.0234"/><polygon fill="#181818" points="627.5,444.0234,617.5,448.0234,627.5,452.0234,623.5,448.0234" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="132" x="623.5" y="429.9575">scheduleTransaction</text><line style="stroke:#181818;stroke-width:1.0;" x1="616.5" x2="658.5" y1="527.2891" y2="527.2891"/><line style="stroke:#181818;stroke-width:1.0;" x1="658.5" x2="658.5" y1="527.2891" y2="540.2891"/><line style="stroke:#181818;stroke-width:1.0;" x1="611.5" x2="658.5" y1="540.2891" y2="540.2891"/><polygon fill="#181818" points="621.5,536.2891,611.5,540.2891,621.5,544.2891,617.5,540.2891" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="92" x="623.5" y="507.0903">sendMessage:</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="157" x="623.5" y="522.2231">EXECUTE_TRANSACTION</text><line style="stroke:#181818;stroke-width:1.0;" x1="611.5" x2="658.5" y1="559.4219" y2="559.4219"/><line style="stroke:#181818;stroke-width:1.0;" x1="658.5" x2="658.5" y1="559.4219" y2="572.4219"/><line style="stroke:#181818;stroke-width:1.0;" x1="617.5" x2="658.5" y1="572.4219" y2="572.4219"/><polygon fill="#181818" points="627.5,568.4219,617.5,572.4219,627.5,576.4219,623.5,572.4219" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="109" x="623.5" y="554.356">handleMessage()</text><polygon fill="#181818" points="775.5,602.5547,785.5,606.5547,775.5,610.5547,779.5,606.5547" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="611.5" x2="781.5" y1="606.5547" y2="606.5547"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="134" x="636.5" y="601.4888">execute(transaction)</text><line style="stroke:#181818;stroke-width:1.0;" x1="797.5" x2="844.5" y1="645.8203" y2="645.8203"/><line style="stroke:#181818;stroke-width:1.0;" x1="844.5" x2="844.5" y1="645.8203" y2="658.8203"/><line style="stroke:#181818;stroke-width:1.0;" x1="803.5" x2="844.5" y1="658.8203" y2="658.8203"/><polygon fill="#181818" points="813.5,654.8203,803.5,658.8203,813.5,662.8203,809.5,658.8203" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="126" x="809.5" y="625.6216">[PauseActivityItem]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="73" x="809.5" y="640.7544">&#8594;execute()</text><polygon fill="#181818" points="627.5,688.9531,617.5,692.9531,627.5,696.9531,623.5,692.9531" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="621.5" x2="791.5" y1="692.9531" y2="692.9531"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="130" x="633.5" y="687.8872">handlePauseActivity</text><polygon fill="#181818" points="930.5,718.0859,940.5,722.0859,930.5,726.0859,934.5,722.0859" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="611.5" x2="936.5" y1="722.0859" y2="722.0859"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="65" x="860.5" y="717.02">onPause()</text><line style="stroke:#181818;stroke-width:1.0;" x1="802.5" x2="844.5" y1="766.3516" y2="766.3516"/><line style="stroke:#181818;stroke-width:1.0;" x1="844.5" x2="844.5" y1="766.3516" y2="779.3516"/><line style="stroke:#181818;stroke-width:1.0;" x1="803.5" x2="844.5" y1="779.3516" y2="779.3516"/><polygon fill="#181818" points="813.5,775.3516,803.5,779.3516,813.5,783.3516,809.5,779.3516" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="126" x="809.5" y="746.1528">[PauseActivityItem]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="91" x="809.5" y="761.2856">&#8594;postExecute</text><polygon fill="#181818" points="497,834.4844,487,838.4844,497,842.4844,493,838.4844" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="491" x2="791.5" y1="838.4844" y2="838.4844"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="94" x="503" y="833.4185">activityPaused</text><polygon fill="#181818" points="149,893.6172,139,897.6172,149,901.6172,145,897.6172" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="143" x2="475" y1="897.6172" y2="897.6172"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="115" x="155" y="892.5513">&#9314; completePause</text><!--SRC=[hLJDJkCm4BxdAInnIOMAEA8UaBAbaP0eL6rMGceG6foXjKZjOBi8Ne3xyWRBe_4aZ1EovA-RhhJ99R5dllc-ppCs3q9ce67333vkKNASeZ6mmY0LAyaqFg4sU2OqSYkKzExKCmkc2tOG7eSdOUWjrV2KHM0UGWsh3KhB3Wz7xEFNRsOiQ3k3hH5ovG-yMampPyGCNsEoJT4bO42rdeHzyS1zWCLwz44O_g2d3x86TMvnSwJkB0ZPHyO96AU2FY_4FV8Ndk8K95cYZsBvXsYaGHeeJ6d25TcL269JrDuhrE1tvOKb-NDtDCR6qczf6ko1w0ILj4byWfss_lCwjOqLN6H0TKjAS-HA9nxAX56dU4Mxp6Pvkz3hjSaHup8vMck4X0s78xOCiYmL75n8iNppyVeMomxtVRiMPk0rGLgmLHUgXxTBNY-Wusb8wTV0Z5Wi9zUJySzeSXlDWyj5C8xEhoxt8xO6cQJbwFbTQYgK9y_8jrPfOk1oCVz5ttv7K5TqXNUZE8nbgx5kOacEbzWx0NTggGzoMy-Kfg5SpQrKCazfD6Yxwl-IbYbZYq2iLgmp_SjEZo759EGCu6if9vBqoUlPhezMvIPk56xSQkvEVcTSRR8KRN4u9TGd]--></g></svg>

<p>在Android 9之前的版本，<code>ActivityThread</code>中通过<code>LAUNCH_ACTIVITY</code>消息来启动activity，源码如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//android\app\ActivityThread.java</span></span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">handleMessage</span><span class="params">(Message msg)</span> &#123;</span><br><span class="line">            <span class="keyword">if</span> (DEBUG_MESSAGES) Slog.v(TAG, <span class="string">&quot;&gt;&gt;&gt; handling: &quot;</span> + codeToString(msg.what));</span><br><span class="line">            <span class="keyword">switch</span> (msg.what) &#123;</span><br><span class="line">                <span class="keyword">case</span> LAUNCH_ACTIVITY: &#123;</span><br><span class="line">                    Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, <span class="string">&quot;activityStart&quot;</span>);</span><br><span class="line">                    <span class="keyword">final</span> <span class="type">ActivityClientRecord</span> <span class="variable">r</span> <span class="operator">=</span> (ActivityClientRecord) msg.obj;</span><br><span class="line"></span><br><span class="line">                    r.packageInfo = getPackageInfoNoCheck(</span><br><span class="line">                            r.activityInfo.applicationInfo, r.compatInfo);</span><br><span class="line">                    handleLaunchActivity(r, <span class="literal">null</span>, <span class="string">&quot;LAUNCH_ACTIVITY&quot;</span>);</span><br><span class="line">                    Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);</span><br><span class="line">                &#125; <span class="keyword">break</span>;</span><br></pre></td></tr></table></figure>

<p>但从Andorid 9开始，<code>ActivityThread</code>去掉了<code>LAUNCH_ACTIVITY</code> <code>PAUSE_ACTIVITY</code> <code>RESUME_ACTIVITY</code>等消息，而是改成了EXECUTE_TRANSACTION，通过ClientTransaction这套机制来执行activity生命周期流程，相关源码如下：</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/93b40782.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/c09f2087.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/c09f2087.html" class="post-title-link" itemprop="url">Android UI 绘制流程</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-09-26 09:45:29" itemprop="dateCreated datePublished" datetime="2023-09-26T09:45:29+08:00">2023-09-26</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2024-01-06 16:11:20" itemprop="dateModified" datetime="2024-01-06T16:11:20+08:00">2024-01-06</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a>
        </span>
    </span>

  
</div>

            <div class="post-description">Android绘制流程</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>Android View的整个绘制流程包含了3个阶段，分别是measure、layout、draw。measure用于计算View的宽高，结果放在<code>mMeasuredWidth</code>和<code>mMeasuredHeight</code>中；layout的作用是计算view及其子view的位置；draw的作用就是将View真正的绘制到显示屏上。</p>
<p>当activity首次启动，或者更新View(如TextView重新设置text)时，都会走到<code>ViewRootImpl.scheduleTraversals</code>来触发View的渲染流程。</p>
<pre class="mermaid">

zenuml
ViewRootImpl.scheduleTraversals {
    &quot;主线程消息循环插入同步屏障&quot;
    Choreographer.&quot;postCallback：mTraversalRunnable&quot; {
        scheduleFrameLocked {
            scheduleVsyncLocked {
                FrameDisplayEventReceiver.scheduleVsync()
            }
        }
    }
}
FrameDisplayEventReceiver.onVsync {
    Looper.&quot;发布一个同步消息&quot;
}
Looper.run {
    Choreographer.doFrame {
        &quot;doCallbacks(Choreographer.CALLBACK_INPUT, ...)&quot;
        &quot;doCallbacks(Choreographer.CALLBACK_ANIMATION,...)&quot;
        &quot;doCallbacks(Choreographer.CALLBACK_INSETS_ANIMATION,...)&quot;
        &quot;doCallbacks(Choreographer.CALLBACK_TRAVERSAL,...)&quot; {
            ViewRootImpl.&quot;mTraversalBarrier.run&quot; {
                ViewRootImpl.doTraversal {
                    &quot;删除同步屏障&quot;
                    performTraversals
                }
            }
        }
        &quot;doCallbacks(Choreographer.CALLBACK_COMMIT,...)&quot;
    }
}
</pre>

<pre class="mermaid">

zenuml
ViewRootImpl.performTraversals {
    measureHierarchy {
        performMeasure {
            DecorView.measure
        }
    }
    relayoutWindow {
        IWindowSession.relayout
        updateBlastSurfaceIfNeeded {
            new BLASTBufferQueue
            blastSurface &#x3D; BLASTBufferQueue.createSurface
            &quot;mSurface.transferFrom(blastSurface)&quot;
        }
        ThreadedRenderer.setSurfaceControl
        ThreadedRenderer.setBlastBufferQueue
    }
    ThreadedRenderer.initialize {
        &quot;HardwareRenderer.setSurface&quot;
    }
    ThreadedRenderer.allocateBuffers
    ThreadedRenderer.setup
    performMeasure {
        DecorView.measure
    }
    performLayout {
        DecorView.layout
    }
    performDraw {
        draw {
            ThreadedRenderer.draw
        }
    }
}
</pre>

<p>关于relayoutWindow的调用流程可参考<a href="/posts/90f60c72.html" title="Android WindowManager与Window">Android WindowManager与Window</a></p>
<p>参考：</p>
<ul>
<li><a target="_blank" rel="noopener external nofollow noreferrer" href="https://blog.csdn.net/tyyj90/article/details/107134945">Android 源码 图形系统之请求布局</a></li>
<li><a target="_blank" rel="noopener external nofollow noreferrer" href="https://blog.csdn.net/zuguorui/article/details/70160323">Android自定义view之measure、layout、draw三大流程</a></li>
</ul>
<h2 id="draw-流程"><a href="#draw-流程" class="headerlink" title="draw() 流程"></a>draw() 流程</h2><p>在自定义View中一般都会用到onDraw这个函数：</p>
<pre class="mermaid">

zenuml
ViewRootImpl.draw {
    if (isHardwareEnabled()) {
        ThreadedRenderer.draw
    } else {
        drawSoftware
    }
}
</pre>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/c09f2087.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/68833f9e.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/68833f9e.html" class="post-title-link" itemprop="url">Bitmap内存分配以及回收</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-09-22 10:36:32" itemprop="dateCreated datePublished" datetime="2023-09-22T10:36:32+08:00">2023-09-22</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-10-18 11:10:27" itemprop="dateModified" datetime="2023-10-18T11:10:27+08:00">2023-10-18</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="Bitmap内存分配"><a href="#Bitmap内存分配" class="headerlink" title="Bitmap内存分配"></a>Bitmap内存分配</h2><ul>
<li>Android 2.3.3 (API level 10)以及更早的Android版本中，Bitmap的像素数据保存在native内存中，像素数据内存的回收则在finalize()中进行回收，存在很大的不确定性，很容易导致OOM的发生；</li>
<li>从Android 3.0 (API level 11) 到Android 7.1 (API level 25)，像素数据存放在Java Heap中，跟Bitmap对象一起回收。但由于图片是内存消耗大户，所以也很容易导致OOM，以及频繁的GC导致内存抖动问题。</li>
<li>在Android 8.0 (API level 26)以及更高的版本中，像素数据保存在native heap中。通过一个辅助类<code>NativeAllocationRegistry</code>来实现native内存的回收。</li>
</ul>
<p>在android.graphics.BitmapFactory类中有一系列函数可以解码生成Bitmap：</p>
<ul>
<li>Bitmap decodeByteArray(byte[] data, int offset, int length)</li>
<li>Bitmap decodeByteArray(byte[] data, int offset, int length, Options opts)</li>
<li>Bitmap decodeFile(String pathName)</li>
<li>Bitmap decodeFile(String pathName, Options opts)</li>
<li>…… 等等</li>
</ul>
<p>这些方法都会调用到jni层<code>frameworks\base\libs\hwui\jni\BitmapFactory.cpp</code>,最终都会走到<code>doDecode</code>方法：</p>
<h3 id="Android-12位图解码，使用native内存"><a href="#Android-12位图解码，使用native内存" class="headerlink" title="Android 12位图解码，使用native内存"></a>Android 12位图解码，使用native内存</h3><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//frameworks\base\libs\hwui\jni\BitmapFactory.cpp</span></span><br><span class="line"><span class="function"><span class="type">static</span> jobject <span class="title">doDecode</span><span class="params">(JNIEnv* env, std::unique_ptr&lt;SkStreamRewindable&gt; stream,</span></span></span><br><span class="line"><span class="params"><span class="function">                        jobject padding, jobject options, jlong inBitmapHandle,</span></span></span><br><span class="line"><span class="params"><span class="function">                        jlong colorSpaceHandle)</span> </span>&#123;</span><br><span class="line">    ...... <span class="comment">//代码省略</span></span><br><span class="line">    <span class="comment">// Scale is necessary due to density differences.</span></span><br><span class="line">    <span class="keyword">if</span> (scale != <span class="number">1.0f</span>) &#123;</span><br><span class="line">        willScale = <span class="literal">true</span>;</span><br><span class="line">        scaledWidth = <span class="built_in">static_cast</span>&lt;<span class="type">int</span>&gt;(scaledWidth * scale + <span class="number">0.5f</span>);</span><br><span class="line">        scaledHeight = <span class="built_in">static_cast</span>&lt;<span class="type">int</span>&gt;(scaledHeight * scale + <span class="number">0.5f</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    android::Bitmap* reuseBitmap = <span class="literal">nullptr</span>;</span><br><span class="line">    <span class="type">unsigned</span> <span class="type">int</span> existingBufferSize = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">if</span> (javaBitmap != <span class="literal">nullptr</span>) &#123;</span><br><span class="line">        reuseBitmap = &amp;bitmap::<span class="built_in">toBitmap</span>(inBitmapHandle);</span><br><span class="line">        <span class="keyword">if</span> (reuseBitmap-&gt;<span class="built_in">isImmutable</span>()) &#123;</span><br><span class="line">            <span class="built_in">ALOGW</span>(<span class="string">&quot;Unable to reuse an immutable bitmap as an image decoder target.&quot;</span>);</span><br><span class="line">            javaBitmap = <span class="literal">nullptr</span>;</span><br><span class="line">            reuseBitmap = <span class="literal">nullptr</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            existingBufferSize = reuseBitmap-&gt;<span class="built_in">getAllocationByteCount</span>();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    HeapAllocator defaultAllocator;</span><br><span class="line">    <span class="function">RecyclingPixelAllocator <span class="title">recyclingAllocator</span><span class="params">(reuseBitmap, existingBufferSize)</span></span>;</span><br><span class="line">    <span class="function">ScaleCheckingAllocator <span class="title">scaleCheckingAllocator</span><span class="params">(scale, existingBufferSize)</span></span>;</span><br><span class="line">    SkBitmap::HeapAllocator heapAllocator;</span><br><span class="line">    SkBitmap::Allocator* decodeAllocator;</span><br><span class="line">    <span class="keyword">if</span> (javaBitmap != <span class="literal">nullptr</span> &amp;&amp; willScale) &#123;</span><br><span class="line">        <span class="comment">// This will allocate pixels using a HeapAllocator, since there will be an extra</span></span><br><span class="line">        <span class="comment">// scaling step that copies these pixels into Java memory.  This allocator</span></span><br><span class="line">        <span class="comment">// also checks that the recycled javaBitmap is large enough.</span></span><br><span class="line">        decodeAllocator = &amp;scaleCheckingAllocator;</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (javaBitmap != <span class="literal">nullptr</span>) &#123;</span><br><span class="line">        decodeAllocator = &amp;recyclingAllocator;</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (willScale || isHardware) &#123;</span><br><span class="line">        <span class="comment">// This will allocate pixels using a HeapAllocator,</span></span><br><span class="line">        <span class="comment">// for scale case: there will be an extra scaling step.</span></span><br><span class="line">        <span class="comment">// for hardware case: there will be extra swizzling &amp; upload to gralloc step.</span></span><br><span class="line">        decodeAllocator = &amp;heapAllocator;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        decodeAllocator = &amp;defaultAllocator;</span><br><span class="line">    &#125;</span><br><span class="line">    ......</span><br><span class="line">    SkBitmap decodingBitmap; <span class="comment">//SkBitmap 是skia库中的类</span></span><br><span class="line">    <span class="comment">//decodingBitmap.tryAllocPixels的作用是分配piexel内存，最终调用的是</span></span><br><span class="line">    <span class="comment">//decodeAllocator-&gt;allocPixelRef(this);</span></span><br><span class="line">    <span class="keyword">if</span> (!decodingBitmap.<span class="built_in">setInfo</span>(bitmapInfo) ||</span><br><span class="line">            !decodingBitmap.<span class="built_in">tryAllocPixels</span>(decodeAllocator)) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">nullptr</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// Use SkAndroidCodec to perform the decode.</span></span><br><span class="line">    SkAndroidCodec::AndroidOptions codecOptions;</span><br><span class="line">    codecOptions.fZeroInitialized = decodeAllocator == &amp;defaultAllocator ?</span><br><span class="line">            SkCodec::kYes_ZeroInitialized : SkCodec::kNo_ZeroInitialized;</span><br><span class="line">    codecOptions.fSampleSize = sampleSize;</span><br><span class="line">    <span class="comment">//codec指的是SkAndroidCodec，是skia库中的类。下面这句代码就是真正的解码了</span></span><br><span class="line">    SkCodec::Result result = codec-&gt;<span class="built_in">getAndroidPixels</span>(decodeInfo, decodingBitmap.<span class="built_in">getPixels</span>(), </span><br><span class="line">            decodingBitmap.<span class="built_in">rowBytes</span>(), &amp;codecOptions);</span><br><span class="line">    </span><br><span class="line">    ......</span><br><span class="line">    <span class="comment">//按比例缩放位图</span></span><br><span class="line">    SkBitmap outputBitmap;</span><br><span class="line">    <span class="keyword">if</span> (willScale) &#123;</span><br><span class="line">        <span class="comment">// Set the allocator for the outputBitmap.</span></span><br><span class="line">        SkBitmap::Allocator* outputAllocator;</span><br><span class="line">        <span class="keyword">if</span> (javaBitmap != <span class="literal">nullptr</span>) &#123;</span><br><span class="line">            outputAllocator = &amp;recyclingAllocator;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            outputAllocator = &amp;defaultAllocator;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        SkColorType scaledColorType = decodingBitmap.<span class="built_in">colorType</span>();</span><br><span class="line">        <span class="comment">// <span class="doctag">FIXME:</span> If the alphaType is kUnpremul and the image has alpha, the</span></span><br><span class="line">        <span class="comment">// colors may not be correct, since Skia does not yet support drawing</span></span><br><span class="line">        <span class="comment">// to/from unpremultiplied bitmaps.</span></span><br><span class="line">        outputBitmap.<span class="built_in">setInfo</span>(</span><br><span class="line">                bitmapInfo.<span class="built_in">makeWH</span>(scaledWidth, scaledHeight).<span class="built_in">makeColorType</span>(scaledColorType));</span><br><span class="line">        <span class="keyword">if</span> (!outputBitmap.<span class="built_in">tryAllocPixels</span>(outputAllocator)) &#123;</span><br><span class="line">            <span class="comment">// This should only fail on OOM.  The recyclingAllocator should have</span></span><br><span class="line">            <span class="comment">// enough memory since we check this before decoding using the</span></span><br><span class="line">            <span class="comment">// scaleCheckingAllocator.</span></span><br><span class="line">            <span class="keyword">return</span> <span class="built_in">nullObjectReturn</span>(<span class="string">&quot;allocation failed for scaled bitmap&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        SkPaint paint;</span><br><span class="line">        <span class="comment">// kSrc_Mode instructs us to overwrite the uninitialized pixels in</span></span><br><span class="line">        <span class="comment">// outputBitmap.  Otherwise we would blend by default, which is not</span></span><br><span class="line">        <span class="comment">// what we want.</span></span><br><span class="line">        paint.<span class="built_in">setBlendMode</span>(SkBlendMode::kSrc);</span><br><span class="line"></span><br><span class="line">        <span class="function">SkCanvas <span class="title">canvas</span><span class="params">(outputBitmap, SkCanvas::ColorBehavior::kLegacy)</span></span>;</span><br><span class="line">        canvas.<span class="built_in">scale</span>(scaleX, scaleY);</span><br><span class="line">        decodingBitmap.<span class="built_in">setImmutable</span>(); <span class="comment">// so .asImage() doesn&#x27;t make a copy</span></span><br><span class="line">        canvas.<span class="built_in">drawImage</span>(decodingBitmap.<span class="built_in">asImage</span>(), <span class="number">0.0f</span>, <span class="number">0.0f</span>,</span><br><span class="line">                         <span class="built_in">SkSamplingOptions</span>(SkFilterMode::kLinear), &amp;paint);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        outputBitmap.<span class="built_in">swap</span>(decodingBitmap);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    ......</span><br><span class="line">    <span class="comment">//硬件位图</span></span><br><span class="line">    <span class="keyword">if</span> (isHardware) &#123;</span><br><span class="line">        <span class="comment">//GPU中分配位图内存。原outputBitmap是否需要释放呢？在哪释放？</span></span><br><span class="line">        sk_sp&lt;Bitmap&gt; hardwareBitmap = Bitmap::<span class="built_in">allocateHardwareBitmap</span>(outputBitmap);</span><br><span class="line">        <span class="keyword">if</span> (!hardwareBitmap.<span class="built_in">get</span>()) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="built_in">nullObjectReturn</span>(<span class="string">&quot;Failed to allocate a hardware bitmap&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//创建java层Bitmap，此处的hardwareBitmap.release()不是资源回收的意思，而是取出sk_sp中的Bitmap实例。</span></span><br><span class="line">        <span class="keyword">return</span> bitmap::<span class="built_in">createBitmap</span>(env, hardwareBitmap.<span class="built_in">release</span>(), bitmapCreateFlags,</span><br><span class="line">                ninePatchChunk, ninePatchInsets, <span class="number">-1</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// now create the java bitmap</span></span><br><span class="line">    <span class="keyword">return</span> bitmap::<span class="built_in">createBitmap</span>(env, defaultAllocator.<span class="built_in">getStorageObjAndReset</span>(),</span><br><span class="line">            bitmapCreateFlags, ninePatchChunk, ninePatchInsets, <span class="number">-1</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="默认pixel内存分配"><a href="#默认pixel内存分配" class="headerlink" title="默认pixel内存分配"></a>默认pixel内存分配</h4><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="type">bool</span> <span class="title">HeapAllocator::allocPixelRef</span><span class="params">(SkBitmap* bitmap)</span> </span>&#123;</span><br><span class="line">    mStorage = android::Bitmap::<span class="built_in">allocateHeapBitmap</span>(bitmap);</span><br><span class="line">    <span class="keyword">return</span> !!mStorage;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//frameworks\base\libs\hwui\hwui\Bitmap.cpp</span></span><br><span class="line"><span class="function">sk_sp&lt;Bitmap&gt; <span class="title">Bitmap::allocateHeapBitmap</span><span class="params">(SkBitmap* bitmap)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="built_in">allocateBitmap</span>(bitmap, &amp;Bitmap::allocateHeapBitmap);</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="type">static</span> sk_sp&lt;Bitmap&gt; <span class="title">allocateBitmap</span><span class="params">(SkBitmap* bitmap, AllocPixelRef alloc)</span> </span>&#123;</span><br><span class="line">    <span class="type">const</span> SkImageInfo&amp; info = bitmap-&gt;<span class="built_in">info</span>();</span><br><span class="line">    <span class="keyword">if</span> (info.<span class="built_in">colorType</span>() == kUnknown_SkColorType) &#123;</span><br><span class="line">        <span class="built_in">LOG_ALWAYS_FATAL</span>(<span class="string">&quot;unknown bitmap configuration&quot;</span>);</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">nullptr</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="type">size_t</span> size;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// we must respect the rowBytes value already set on the bitmap instead of</span></span><br><span class="line">    <span class="comment">// attempting to compute our own.</span></span><br><span class="line">    <span class="type">const</span> <span class="type">size_t</span> rowBytes = bitmap-&gt;<span class="built_in">rowBytes</span>();</span><br><span class="line">    <span class="keyword">if</span> (!Bitmap::<span class="built_in">computeAllocationSize</span>(rowBytes, bitmap-&gt;<span class="built_in">height</span>(), &amp;size)) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">nullptr</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">auto</span> wrapper = <span class="built_in">alloc</span>(size, info, rowBytes); <span class="comment">//使用入参的alloc函数分配内存</span></span><br><span class="line">    <span class="keyword">if</span> (wrapper) &#123;</span><br><span class="line">        wrapper-&gt;<span class="built_in">getSkBitmap</span>(bitmap);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> wrapper;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function">sk_sp&lt;Bitmap&gt; <span class="title">Bitmap::allocateHeapBitmap</span><span class="params">(<span class="type">size_t</span> size, <span class="type">const</span> SkImageInfo&amp; info, <span class="type">size_t</span> rowBytes)</span> </span>&#123;</span><br><span class="line">    <span class="type">void</span>* addr = <span class="built_in">calloc</span>(size, <span class="number">1</span>); <span class="comment">//调用Linux C库函数分配内存</span></span><br><span class="line">    <span class="keyword">if</span> (!addr) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">nullptr</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="built_in">sk_sp</span>&lt;Bitmap&gt;(<span class="keyword">new</span> <span class="built_in">Bitmap</span>(addr, size, info, rowBytes)); <span class="comment">//返回最终的Bitmap对象</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="比例缩放或硬件位图场景内存分配"><a href="#比例缩放或硬件位图场景内存分配" class="headerlink" title="比例缩放或硬件位图场景内存分配"></a>比例缩放或硬件位图场景内存分配</h4>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/68833f9e.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/f45b8d80.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/f45b8d80.html" class="post-title-link" itemprop="url">Java注解原理</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-09-21 17:46:38" itemprop="dateCreated datePublished" datetime="2023-09-21T17:46:38+08:00">2023-09-21</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-10-18 16:02:14" itemprop="dateModified" datetime="2023-10-18T16:02:14+08:00">2023-10-18</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a>
        </span>
    </span>

  
</div>

            <div class="post-description">Java注解原理</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>注解的使用场景可以分为两种：一）编译期间通过注解解析器处理；2）运行期间反射使用；</p>
<h2 id="注解保留策略"><a href="#注解保留策略" class="headerlink" title="注解保留策略"></a>注解保留策略</h2><ul>
<li><code>RetentionPolicy.SOURCE</code> : 编译期可见，但不会写入到.class文件；</li>
<li><code>RetentionPolicy#CLASS</code> : 会写入到.class文件中，但是会被JVM忽略（这是默认策略）；</li>
<li><code>RetentionPolicy#RUNTIME</code> ：注解会被写入到.class文件中，并且JVM运行期间也可见，可以通过反射放射获取到；</li>
</ul>
<h3 id="注解的定义"><a href="#注解的定义" class="headerlink" title="注解的定义"></a>注解的定义</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Target(&#123;ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.PARAMETER&#125;)</span></span><br><span class="line"><span class="meta">@Retention(RetentionPolicy.CLASS)</span></span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> MyClass &#123;</span><br><span class="line">    String <span class="title function_">name</span><span class="params">()</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Target(&#123;ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR&#125;)</span></span><br><span class="line"><span class="meta">@Retention(RetentionPolicy.RUNTIME)</span></span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> MyRuntime1 &#123;</span><br><span class="line">    <span class="type">int</span> <span class="title function_">id</span><span class="params">()</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Target(&#123;ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR&#125;)</span></span><br><span class="line"><span class="meta">@Retention(RetentionPolicy.RUNTIME)</span></span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> MyRuntime2 &#123;&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Target(&#123;ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR&#125;)</span></span><br><span class="line"><span class="meta">@Retention(RetentionPolicy.SOURCE)</span></span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> MySource &#123;&#125;</span><br></pre></td></tr></table></figure>

<p>编译完成后，每个注解都会生成自己的.class文件，看一下MyClass这个注解的.class文件的内容：</p>
<figure class="highlight text"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line">$ javap -p -v me/demo/MyClass.class</span><br><span class="line">Picked up JAVA_TOOL_OPTIONS: -Duser.language=en -Dfile.encoding=UTF-8</span><br><span class="line">Classfile /F:/demo/JavaDemo/out/production/JavaDemo/me/demo/MyClass.class</span><br><span class="line">  Last modified Sep 21, 2023; size 472 bytes</span><br><span class="line">  MD5 checksum cb49d6b6a5ed7ab9c2b85d731996fb5f</span><br><span class="line">  Compiled from &quot;MyClass.java&quot;</span><br><span class="line">public interface me.demo.MyClass extends java.lang.annotation.Annotation</span><br><span class="line">  minor version: 0</span><br><span class="line">  major version: 61</span><br><span class="line">  flags: (0x2601) ACC_PUBLIC, ACC_INTERFACE, ACC_ABSTRACT, ACC_ANNOTATION</span><br><span class="line">  this_class: #1                          // me/demo/MyClass</span><br><span class="line">  super_class: #3                         // java/lang/Object</span><br><span class="line">  interfaces: 1, fields: 0, methods: 1, attributes: 2</span><br><span class="line">Constant pool:</span><br><span class="line">   #1 = Class              #2             // me/demo/MyClass</span><br><span class="line">   #2 = Utf8               me/demo/MyClass</span><br><span class="line">   #3 = Class              #4             // java/lang/Object</span><br><span class="line">   #4 = Utf8               java/lang/Object</span><br><span class="line">   #5 = Class              #6             // java/lang/annotation/Annotation</span><br><span class="line">   #6 = Utf8               java/lang/annotation/Annotation</span><br><span class="line">   #7 = Utf8               name</span><br><span class="line">   #8 = Utf8               ()Ljava/lang/String;</span><br><span class="line">   #9 = Utf8               SourceFile</span><br><span class="line">  #10 = Utf8               MyClass.java</span><br><span class="line">  #11 = Utf8               RuntimeVisibleAnnotations</span><br><span class="line">  #12 = Utf8               Ljava/lang/annotation/Target;</span><br><span class="line">  #13 = Utf8               value</span><br><span class="line">  #14 = Utf8               Ljava/lang/annotation/ElementType;</span><br><span class="line">  #15 = Utf8               TYPE</span><br><span class="line">  #16 = Utf8               METHOD</span><br><span class="line">  #17 = Utf8               FIELD</span><br><span class="line">  #18 = Utf8               CONSTRUCTOR</span><br><span class="line">  #19 = Utf8               PARAMETER</span><br><span class="line">  #20 = Utf8               Ljava/lang/annotation/Retention;</span><br><span class="line">  #21 = Utf8               Ljava/lang/annotation/RetentionPolicy;</span><br><span class="line">  #22 = Utf8               CLASS</span><br><span class="line">&#123;</span><br><span class="line">  public abstract java.lang.String name();</span><br><span class="line">    descriptor: ()Ljava/lang/String;</span><br><span class="line">    flags: (0x0401) ACC_PUBLIC, ACC_ABSTRACT</span><br><span class="line">&#125;</span><br><span class="line">SourceFile: &quot;MyClass.java&quot;</span><br><span class="line">RuntimeVisibleAnnotations:</span><br><span class="line">  0: #12(#13=[e#14.#15,e#14.#16,e#14.#17,e#14.#18,e#14.#19])</span><br><span class="line">    java.lang.annotation.Target(</span><br><span class="line">      value=[Ljava/lang/annotation/ElementType;.TYPE,Ljava/lang/annotation/ElementType;.METHOD,Ljava/lang/annotation/ElementType;.FIELD,Ljava/lang/annotation/ElementType;.CONSTRUCTOR,Ljava/lang/annotation/ElementType;.PARAMETER]</span><br><span class="line">    )</span><br><span class="line">  1: #20(#13=e#21.#22)</span><br><span class="line">    java.lang.annotation.Retention(</span><br><span class="line">      value=Ljava/lang/annotation/RetentionPolicy;.CLASS</span><br><span class="line">    )</span><br></pre></td></tr></table></figure>

<p>从MyClass.class文件第7行代码<code>public interface MyClass extends java.lang.annotation.Annotation</code>可以看出来MyClass实际上是继承自Annotation的接口类。这一点从<code>java.lang.Class#getAnnotation</code>这个方法也可以看出来：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//java/lang/Class.java</span></span><br><span class="line">    <span class="keyword">public</span> &lt;A <span class="keyword">extends</span> <span class="title class_">Annotation</span>&gt; A <span class="title function_">getAnnotation</span><span class="params">(Class&lt;A&gt; annotationClass)</span> &#123;</span><br><span class="line">        Objects.requireNonNull(annotationClass);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> (A) annotationData().annotations.get(annotationClass);</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<h3 id="注解的使用"><a href="#注解的使用" class="headerlink" title="注解的使用"></a>注解的使用</h3>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/f45b8d80.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/d01e7370.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/d01e7370.html" class="post-title-link" itemprop="url">Android View Measure源码分析</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>
      

      <time title="创建时间：2023-09-19 11:10:48 / 修改时间：16:21:32" itemprop="dateCreated datePublished" datetime="2023-09-19T11:10:48+08:00">2023-09-19</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a>
        </span>
    </span>

  
</div>

            <div class="post-description">Android View Measure源码分析</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>在<a href="/posts/11962.html" title="Android Activity启动流程">Android Activity启动流程</a>文章中已经介绍了，在activity的onResume之后，<code>ViewRootImpl#setView(View view, WindowManager.LayoutParams attrs, ...)</code>，其中view就是DecorView，ViewRootImpl#setView中就会调用<code>requestLayout</code>，然后调用<code>scheduleTraversals</code>。这是首次调用，后续view的改动都会调用到<code>scheduleTraversals</code>。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//android-12.1.0_r27\frameworks\base\core\java\android\view\ViewRootImpl.java</span></span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">scheduleTraversals</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">if</span> (!mTraversalScheduled) &#123;</span><br><span class="line">            mTraversalScheduled = <span class="literal">true</span>;</span><br><span class="line">            <span class="comment">//添加同步屏障，主线程的同步消息都会进制执行，保证vsync信号到来时TraversalRunnable能够立刻被执行</span></span><br><span class="line">            mTraversalBarrier = mHandler.getLooper().getQueue().postSyncBarrier();</span><br><span class="line">            mChoreographer.postCallback(</span><br><span class="line">                    Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, <span class="literal">null</span>);</span><br><span class="line">            notifyRendererOfFramePending();</span><br><span class="line">            pokeDrawLockIfNeeded();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">final</span> <span class="type">TraversalRunnable</span> <span class="variable">mTraversalRunnable</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">TraversalRunnable</span>();</span><br><span class="line"></span><br><span class="line">    <span class="keyword">final</span> <span class="keyword">class</span> <span class="title class_">TraversalRunnable</span> <span class="keyword">implements</span> <span class="title class_">Runnable</span> &#123;</span><br><span class="line">        <span class="meta">@Override</span></span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">run</span><span class="params">()</span> &#123;</span><br><span class="line">            doTraversal();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">doTraversal</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">if</span> (mTraversalScheduled) &#123;</span><br><span class="line">            mTraversalScheduled = <span class="literal">false</span>;</span><br><span class="line">            <span class="comment">//删除同步屏障</span></span><br><span class="line">            mHandler.getLooper().getQueue().removeSyncBarrier(mTraversalBarrier);</span><br><span class="line"></span><br><span class="line">            <span class="keyword">if</span> (mProfile) &#123;</span><br><span class="line">                Debug.startMethodTracing(<span class="string">&quot;ViewAncestor&quot;</span>);</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            performTraversals();</span><br><span class="line"></span><br><span class="line">            <span class="keyword">if</span> (mProfile) &#123;</span><br><span class="line">                Debug.stopMethodTracing();</span><br><span class="line">                mProfile = <span class="literal">false</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/d01e7370.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/e679f521.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/e679f521.html" class="post-title-link" itemprop="url">图解RecyclerView缓存机制</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-09-19 09:20:14" itemprop="dateCreated datePublished" datetime="2023-09-19T09:20:14+08:00">2023-09-19</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-10-18 14:00:25" itemprop="dateModified" datetime="2023-10-18T14:00:25+08:00">2023-10-18</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentstyletype="text/css" height="451px" preserveAspectRatio="none" style="width:319px;height:451px;background:#FFFFFF;" version="1.1" viewBox="0 0 319 451" width="319px" zoomAndPan="magnify"><defs/><g><!--class ViewGroup--><g id="elem_ViewGroup"><rect fill="#F1F1F1" height="48" id="ViewGroup" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="110" x="27.5" y="7"/><ellipse cx="42.5" cy="23" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M44.8438,18.6719 C43.9063,18.2344 43.3125,18.0938 42.4375,18.0938 C39.8125,18.0938 37.8125,20.1719 37.8125,22.8906 L37.8125,24.0156 C37.8125,26.5938 39.9219,28.4844 42.8125,28.4844 C44.0313,28.4844 45.1875,28.1875 45.9375,27.6406 C46.5156,27.2344 46.8438,26.7813 46.8438,26.3906 C46.8438,25.9375 46.4531,25.5469 45.9844,25.5469 C45.7656,25.5469 45.5625,25.625 45.375,25.8125 C44.9219,26.2969 44.9219,26.2969 44.7344,26.3906 C44.3125,26.6563 43.625,26.7813 42.8594,26.7813 C40.8125,26.7813 39.5156,25.6875 39.5156,23.9844 L39.5156,22.8906 C39.5156,21.1094 40.7656,19.7969 42.5,19.7969 C43.0781,19.7969 43.6875,19.9531 44.1563,20.2031 C44.6406,20.4844 44.8125,20.7031 44.9063,21.1094 C44.9688,21.5156 45,21.6406 45.1406,21.7656 C45.2813,21.9063 45.5156,22.0156 45.7344,22.0156 C46,22.0156 46.2656,21.875 46.4375,21.6563 C46.5469,21.5 46.5781,21.3125 46.5781,20.8906 L46.5781,19.4688 C46.5781,19.0313 46.5625,18.9063 46.4688,18.75 C46.3125,18.4844 46.0313,18.3438 45.7344,18.3438 C45.4375,18.3438 45.2344,18.4375 45.0156,18.75 L44.8438,18.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="78" x="56.5" y="27.8467">ViewGroup</text><line style="stroke:#181818;stroke-width:0.5;" x1="28.5" x2="136.5" y1="39" y2="39"/><line style="stroke:#181818;stroke-width:0.5;" x1="28.5" x2="136.5" y1="47" y2="47"/></g><!--class RecyclerView--><g id="elem_RecyclerView"><rect fill="#F1F1F1" height="48" id="RecyclerView" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="128" x="95.5" y="115"/><ellipse cx="110.5" cy="131" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M112.8438,126.6719 C111.9063,126.2344 111.3125,126.0938 110.4375,126.0938 C107.8125,126.0938 105.8125,128.1719 105.8125,130.8906 L105.8125,132.0156 C105.8125,134.5938 107.9219,136.4844 110.8125,136.4844 C112.0313,136.4844 113.1875,136.1875 113.9375,135.6406 C114.5156,135.2344 114.8438,134.7813 114.8438,134.3906 C114.8438,133.9375 114.4531,133.5469 113.9844,133.5469 C113.7656,133.5469 113.5625,133.625 113.375,133.8125 C112.9219,134.2969 112.9219,134.2969 112.7344,134.3906 C112.3125,134.6563 111.625,134.7813 110.8594,134.7813 C108.8125,134.7813 107.5156,133.6875 107.5156,131.9844 L107.5156,130.8906 C107.5156,129.1094 108.7656,127.7969 110.5,127.7969 C111.0781,127.7969 111.6875,127.9531 112.1563,128.2031 C112.6406,128.4844 112.8125,128.7031 112.9063,129.1094 C112.9688,129.5156 113,129.6406 113.1406,129.7656 C113.2813,129.9063 113.5156,130.0156 113.7344,130.0156 C114,130.0156 114.2656,129.875 114.4375,129.6563 C114.5469,129.5 114.5781,129.3125 114.5781,128.8906 L114.5781,127.4688 C114.5781,127.0313 114.5625,126.9063 114.4688,126.75 C114.3125,126.4844 114.0313,126.3438 113.7344,126.3438 C113.4375,126.3438 113.2344,126.4375 113.0156,126.75 L112.8438,126.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="96" x="124.5" y="135.8467">RecyclerView</text><line style="stroke:#181818;stroke-width:0.5;" x1="96.5" x2="222.5" y1="147" y2="147"/><line style="stroke:#181818;stroke-width:0.5;" x1="96.5" x2="222.5" y1="155" y2="155"/></g><!--class ScrollingView--><g id="elem_ScrollingView"><rect codeline="2" fill="#F1F1F1" height="48" id="ScrollingView" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="128" x="172.5" y="7"/><ellipse cx="187.5" cy="23" fill="#B4A7E5" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M188.4531,19.7813 L190.1719,19.7813 C190.5625,19.7813 190.75,19.75 190.875,19.6719 C191.1406,19.5156 191.2813,19.2344 191.2813,18.9375 C191.2813,18.6719 191.1719,18.4063 190.9375,18.2344 C190.7656,18.125 190.625,18.0938 190.1719,18.0938 L185.0313,18.0938 C184.5938,18.0938 184.4688,18.1094 184.3125,18.2031 C184.0625,18.3594 183.9063,18.6563 183.9063,18.9375 C183.9063,19.2188 184.0469,19.4688 184.2656,19.6406 C184.4219,19.75 184.6094,19.7813 185.0313,19.7813 L186.75,19.7813 L186.75,26.2969 L185.0313,26.2969 C184.5938,26.2969 184.4688,26.3125 184.3125,26.4219 C184.0625,26.5781 183.9063,26.8594 183.9063,27.1563 C183.9063,27.4063 184.0469,27.6719 184.2656,27.8281 C184.4219,27.9531 184.625,28 185.0313,28 L190.1719,28 C190.9219,28 191.2813,27.7188 191.2813,27.1563 C191.2813,26.875 191.1719,26.625 190.9375,26.4531 C190.7656,26.3281 190.625,26.2969 190.1719,26.2969 L188.4531,26.2969 L188.4531,19.7813 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="96" x="201.5" y="27.8467">ScrollingView</text><line style="stroke:#181818;stroke-width:0.5;" x1="173.5" x2="299.5" y1="39" y2="39"/><line style="stroke:#181818;stroke-width:0.5;" x1="173.5" x2="299.5" y1="47" y2="47"/></g><!--class Recycler--><g id="elem_Recycler"><rect codeline="4" fill="#F1F1F1" height="113.1875" id="Recycler" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="305" x="7" y="223"/><ellipse cx="124.25" cy="239" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M126.5938,234.6719 C125.6563,234.2344 125.0625,234.0938 124.1875,234.0938 C121.5625,234.0938 119.5625,236.1719 119.5625,238.8906 L119.5625,240.0156 C119.5625,242.5938 121.6719,244.4844 124.5625,244.4844 C125.7813,244.4844 126.9375,244.1875 127.6875,243.6406 C128.2656,243.2344 128.5938,242.7813 128.5938,242.3906 C128.5938,241.9375 128.2031,241.5469 127.7344,241.5469 C127.5156,241.5469 127.3125,241.625 127.125,241.8125 C126.6719,242.2969 126.6719,242.2969 126.4844,242.3906 C126.0625,242.6563 125.375,242.7813 124.6094,242.7813 C122.5625,242.7813 121.2656,241.6875 121.2656,239.9844 L121.2656,238.8906 C121.2656,237.1094 122.5156,235.7969 124.25,235.7969 C124.8281,235.7969 125.4375,235.9531 125.9063,236.2031 C126.3906,236.4844 126.5625,236.7031 126.6563,237.1094 C126.7188,237.5156 126.75,237.6406 126.8906,237.7656 C127.0313,237.9063 127.2656,238.0156 127.4844,238.0156 C127.75,238.0156 128.0156,237.875 128.1875,237.6563 C128.2969,237.5 128.3281,237.3125 128.3281,236.8906 L128.3281,235.4688 C128.3281,235.0313 128.3125,234.9063 128.2188,234.75 C128.0625,234.4844 127.7813,234.3438 127.4844,234.3438 C127.1875,234.3438 126.9844,234.4375 126.7656,234.75 L126.5938,234.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="62" x="144.75" y="243.8467">Recycler</text><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="311" y1="255" y2="255"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="293" x="13" y="271.9951">ArrayList&lt;ViewHolder&gt; mAttachedScrap</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="289" x="13" y="288.292">ArrayList&lt;ViewHolder&gt; mChangedScrap</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="279" x="13" y="304.5889">ArrayList&lt;ViewHolder&gt; mCachedViews</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="241" x="13" y="320.8857">RecycledViewPool mRecyclerPool</text><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="311" y1="328.1875" y2="328.1875"/></g><!--class RecycledViewPool--><g id="elem_RecycledViewPool"><rect fill="#F1F1F1" height="48" id="RecycledViewPool" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="162" x="78.5" y="396"/><ellipse cx="93.5" cy="412" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M95.8438,407.6719 C94.9063,407.2344 94.3125,407.0938 93.4375,407.0938 C90.8125,407.0938 88.8125,409.1719 88.8125,411.8906 L88.8125,413.0156 C88.8125,415.5938 90.9219,417.4844 93.8125,417.4844 C95.0313,417.4844 96.1875,417.1875 96.9375,416.6406 C97.5156,416.2344 97.8438,415.7813 97.8438,415.3906 C97.8438,414.9375 97.4531,414.5469 96.9844,414.5469 C96.7656,414.5469 96.5625,414.625 96.375,414.8125 C95.9219,415.2969 95.9219,415.2969 95.7344,415.3906 C95.3125,415.6563 94.625,415.7813 93.8594,415.7813 C91.8125,415.7813 90.5156,414.6875 90.5156,412.9844 L90.5156,411.8906 C90.5156,410.1094 91.7656,408.7969 93.5,408.7969 C94.0781,408.7969 94.6875,408.9531 95.1563,409.2031 C95.6406,409.4844 95.8125,409.7031 95.9063,410.1094 C95.9688,410.5156 96,410.6406 96.1406,410.7656 C96.2813,410.9063 96.5156,411.0156 96.7344,411.0156 C97,411.0156 97.2656,410.875 97.4375,410.6563 C97.5469,410.5 97.5781,410.3125 97.5781,409.8906 L97.5781,408.4688 C97.5781,408.0313 97.5625,407.9063 97.4688,407.75 C97.3125,407.4844 97.0313,407.3438 96.7344,407.3438 C96.4375,407.3438 96.2344,407.4375 96.0156,407.75 L95.8438,407.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="130" x="107.5" y="416.8467">RecycledViewPool</text><line style="stroke:#181818;stroke-width:0.5;" x1="79.5" x2="239.5" y1="428" y2="428"/><line style="stroke:#181818;stroke-width:0.5;" x1="79.5" x2="239.5" y1="436" y2="436"/></g><!--reverse link ViewGroup to RecyclerView--><g id="link_ViewGroup_RecyclerView"><path codeline="1" d="M109.7869,69.5632 C122.614,87.2212 129.674,96.941 142.559,114.678 " fill="none" id="ViewGroup-backto-RecyclerView" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="99.2079,55,104.9325,73.0895,114.6412,66.0368,99.2079,55" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link ScrollingView to RecyclerView--><g id="link_ScrollingView_RecyclerView"><path codeline="3" d="M209.2131,69.5632 C196.3861,87.2212 189.326,96.941 176.441,114.678 " fill="none" id="ScrollingView-backto-RecyclerView" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:7.0,7.0;"/><polygon fill="none" points="219.792,55,204.3587,66.0369,214.0675,73.0895,219.792,55" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link RecyclerView to Recycler--><g id="link_RecyclerView_Recycler"><path codeline="10" d="M159.5,175.182 C159.5,191.507 159.5,202.084 159.5,222.937 " fill="none" id="RecyclerView-backto-Recycler" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="159.5,163.182,155.5,169.182,159.5,175.182,163.5,169.182,159.5,163.182" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link Recycler to RecycledViewPool--><g id="link_Recycler_RecycledViewPool"><path codeline="11" d="M159.5,348.035 C159.5,368.9568 159.5,379.6181 159.5,395.9619 " fill="none" id="Recycler-backto-RecycledViewPool" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="159.5,336.035,155.5,342.035,159.5,348.035,163.5,342.035,159.5,336.035" style="stroke:#181818;stroke-width:1.0;"/></g><!--SRC=[2yjCBNSloYyjKB2fqTLL24fDhapEIIqA0mfpPUQLf1Qb9IQdAWGd5-Ndv6JcfOF5KNX0VNfwgFgISnABY-522jLS2a3WM5IKMEcJMLnY0rBZaP-Jabfafv3hM5AIc9oHcW8qCx40dqBdZCIyT6BKWOq32HM3bK6T0HO9oC_FKSY5EGp4uwhbGdQwWXPI6C1ba4NXvW00]--></g></svg>

<h2 id="删除View缓存使用图解"><a href="#删除View缓存使用图解" class="headerlink" title="删除View缓存使用图解"></a>删除View缓存使用图解</h2><p><img src="/images/RecyclerView/remove_item.drawio.svg" alt="RecyclerView移除元素"></p>
<p>在垂直布局的RecyclerView中展示了Item0~Item4这5个TextView，我们现在把Item2删掉。数据更新后，我们调用<code>Adapter#notifyItemRemoved(2)</code>来提交更新。</p>
<p><img src="/images/RecyclerView/remove_item_cache_use_sequence.drawio.svg" alt="RecyclerView删除Item"></p>
<p><strong>dispatchLayoutStep1阶段：</strong></p>
<ol>
<li>调用detachViewFromParent把Item0~Item4这五个View从RecyclerView中detache掉，然后放入把ViewHolder放入mAttachedScrap进行缓存。ViewHodler都会被标记为FLAG_TMP_DETACHED，并且Item2会被标记为FLAG_REMOVED；</li>
<li>然后layout进行填充，把Item0~Item4从mAttachedScrap中取出，然后调用attachViewToParent重新加入到RecyclerView中。</li>
<li>调用onCreateViewHolder创建一个新ViewHolder（Item5），执行onBindViewHolder，并addView到RecyclerView中。</li>
</ol>
<p><strong>dispatchLayoutStep2阶段：</strong></p>
<ol>
<li>调用detachViewFromParent把Item0~Item5这六个View从RecyclerView中detache掉，然后把ViewHolder放入mAttachedScrap进行缓存。ViewHolder都会被标记为FLAG_TMP_DETACHED，并且Item2会被标记为FLAG_REMOVED；</li>
<li>除了Item2的ViewHolder之外，把其他ViewHolder从mAttachedScrap缓存中取出，然后调用attachViewToParent重新加入到RecyclerView中。</li>
</ol>
<p><strong>dispatchLayoutStep3阶段：</strong></p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/e679f521.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




  <nav class="pagination">
    <a class="extend prev" rel="prev" title="上一页" aria-label="上一页" href="/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/">1</a><span class="page-number current">2</span><a class="page-number" href="/page/3/">3</a><span class="space">&hellip;</span><a class="page-number" href="/page/7/">7</a><a class="extend next" rel="next" title="下一页" aria-label="下一页" href="/page/3/"><i class="fa fa-angle-right"></i></a>
  </nav>

</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 
    <span itemprop="copyrightYear">2024</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">Jason</span>
  </div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener external nofollow noreferrer" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/pisces/" rel="noopener external nofollow noreferrer" target="_blank">NexT.Pisces</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.24/fancybox/fancybox.umd.js" integrity="sha256-oyhjPiYRWGXaAt+ny/mTMWOnN1GBoZDUQnzzgC7FRI4=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>


  <script class="next-config" data-name="mermaid" type="application/json">{"enable":true,"theme":{"light":"default","dark":"dark"},"js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.5.0/mermaid.min.js","integrity":"sha256-K7oJiQlDulzl24ZUFOywuYme1JqBBvQzK6m8qHjt9Gk="}}</script>
  <script type="module" src="/js/zenuml-definition-074a43fa.js"></script>
  <script type="module" src="/js/mermaid-zenuml.esm.min.mjs"></script>
  <script src="/js/third-party/tags/mermaid.js"></script>


  <script src="/js/third-party/fancybox.js"></script>



  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>



</body>
</html>
